github.heygears.com/openimsdk/tools@v0.0.49/.github/workflows/milestone.yml (about)

     1  # Copyright © 2023 OpenIM. All rights reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  # shamelessly copied from https://github.com/sigstore/cosign/blob/main/.github/workflows/milestone.yaml
    16  
    17  name: milestone
    18  
    19  on:
    20    pull_request_target:
    21      types: [closed]
    22      branches:
    23        - main
    24  
    25  jobs:
    26    milestone:
    27      runs-on: ubuntu-latest
    28  
    29      permissions:
    30        actions: none
    31        checks: none
    32        contents: read
    33        deployments: none
    34        issues: write
    35        packages: none
    36        pull-requests: write
    37        repository-projects: none
    38        security-events: none
    39        statuses: none
    40  
    41      steps:
    42        - uses: actions/github-script@v7 # v6
    43          with:
    44            script: |
    45              if (!context.payload.pull_request.merged) {
    46                console.log('PR was not merged, skipping.');
    47                return;
    48              }
    49  
    50              if (!!context.payload.pull_request.milestone) {
    51                console.log('PR has existing milestone, skipping.');
    52                return;
    53              }
    54  
    55              milestones = await github.rest.issues.listMilestones({
    56                owner: context.repo.owner,
    57                repo: context.repo.repo,
    58                state: 'open',
    59                sort: 'due_on',
    60                direction: 'asc'
    61              })
    62              if (milestones.data.length === 0) {
    63                console.log('There are no milestones, skipping.');
    64                return;
    65              }
    66  
    67              await github.rest.issues.update({
    68                owner: context.repo.owner,
    69                repo: context.repo.repo,
    70                issue_number: context.payload.pull_request.number,
    71                milestone: milestones.data[0].number
    72              });