github.heygears.com/openimsdk/tools@v0.0.49/.github/workflows/bot-auto-cherry-pick.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 name: Github Rebot for Cherry Pick when PR is merged 16 on: 17 pull_request_target: 18 types: 19 - closed 20 21 jobs: 22 comment: 23 runs-on: ubuntu-latest 24 steps: 25 - name: Comment cherry-pick command 26 uses: actions/github-script@v7 27 with: 28 script: | 29 const pr = context.payload.pull_request; 30 if (!pr.merged) { 31 console.log("PR is not merged. Skipping..."); 32 return; 33 } 34 if (!pr.milestone || !pr.milestone.title) { 35 console.log("Milestone is not set. Skipping..."); 36 return; 37 } 38 const milestone = pr.milestone.title; 39 const ref = `heads/release-${milestone}`; 40 let branchExists; 41 try { 42 await github.rest.git.getRef({ 43 owner: context.repo.owner, 44 repo: context.repo.repo, 45 ref: ref 46 }); 47 branchExists = true; 48 } catch (error) { 49 if (error.status === 404) { 50 console.log(`Branch ${ref} does not exist. Skipping...`); 51 branchExists = false; 52 } else { 53 throw error; // Rethrow if it's another error 54 } 55 } 56 if (!branchExists) { 57 return; 58 } 59 const cherryPickCmd = `/cherry-pick release-${milestone}`; 60 console.log(`Adding comment: ${cherryPickCmd}`); 61 await github.rest.issues.createComment({ 62 owner: context.repo.owner, 63 repo: context.repo.repo, 64 issue_number: pr.number, 65 body: cherryPickCmd 66 }); 67 github-token: ${{ secrets.BOT_GITHUB_TOKEN }}