Skip to content

Commit

Permalink
feat(workflows): optimizing pull request greeting message (#2765)
Browse files Browse the repository at this point in the history
Co-authored-by: Zoom Chan <zoom_chan@163.com>
  • Loading branch information
medns and zoomchan-cxj committed Feb 6, 2023
1 parent 336eb3f commit 0abfcc0
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 22 deletions.
22 changes: 0 additions & 22 deletions .github/workflows/gh_pr_checks_approval.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ on:
- main

env:
greetings_message: |
👋 Thanks for your contributing!
Our collaborators will review your pull request after all status checks have been passed.
safety_changes_message: |
After a quick scan, I have approved%sworkflow%s to run.
risky_changes_message: |
Expand All @@ -21,26 +17,8 @@ env:
jobs:
pull_request_checks_approval:
if: github.repository == 'Tencent/Hippy'
permissions:
actions: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Greetings
if: github.event.action == 'opened'
uses: actions/github-script@v6.3.3
with:
script: |
const { owner, repo } = context.repo;
const { pull_request } = context.payload;
const { issues } = github.rest;
await issues.createComment({
owner,
repo,
issue_number: pull_request.number,
body: process.env['greetings_message'],
});
- name: Token
uses: navikt/github-app-token-generator@v1
id: get-token
Expand Down
105 changes: 105 additions & 0 deletions .github/workflows/gh_pr_guide.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: '[gh] pull request guide'

on:
pull_request_target:
branches:
- master
- main
- v3.0-dev
- v3.0
types:
- opened
issue_comment:
types:
- created

jobs:
pull_request_greetings:
if: github.event.action == 'opened' && github.repository == 'Tencent/Hippy'
runs-on: ubuntu-latest
env:
MESSAGE: |
Hi, @${{ github.event.sender.login }}. Thanks for your PR! :clap:
:label: You can leave a comment in this PR with **`#help`** tag when you need help (e.g. some status checks run failed due to internal issue), admin team members will help asap.
steps:
- name: Token
uses: navikt/github-app-token-generator@v1
id: get-token
with:
private-key: ${{ secrets.PRIVATE_KEY }}
app-id: ${{ secrets.APP_ID }}
- name: Greetings
uses: actions/github-script@v6.1.0
with:
github-token: ${{ steps.get-token.outputs.token }}
script: |
const { owner, repo } = context.repo;
const { pull_request } = context.payload;
const { issues } = github.rest;
await issues.createComment({
owner,
repo,
issue_number: pull_request.number,
body: process.env.MESSAGE,
});
pull_request_help_needed:
if: github.event.sender.type == 'User' && github.event.issue.pull_request && contains(github.event.comment.body, '#help') && github.repository == 'Tencent/Hippy'
runs-on: ubuntu-latest
env:
MESSAGE: |
[${{ github.event.sender.login }}](https://github.com/${{ github.event.sender.login }}) needs help on [#${{ github.event.issue.number }}](${{ github.event.comment.html_url }}) pull request.
> [${{ github.event.comment.html_url }}](${{ github.event.comment.html_url }})
> ${{ github.event.comment.body }}
steps:
- name: Token
uses: navikt/github-app-token-generator@v1
id: get-token
with:
private-key: ${{ secrets.PRIVATE_KEY }}
app-id: ${{ secrets.APP_ID }}
- name: Action
uses: actions/github-script@v6.3.3
with:
github-token: ${{ steps.get-token.outputs.token }}
script: |
const { owner, repo } = context.repo;
const { issue } = context.payload;
const { issues } = github.rest;
const p = [];
p.push(issues.addLabels({
issue_number: issue.number,
labels: [ 'needs: help' ],
...context.repo,
}));
p.push(github.request("POST ${{ secrets.WECHAT_WORK_BOT_WEBHOOK }}", {
headers: {
"content-type": "application/json"
},
data: {
chatid: "${{ secrets.WECHAT_WORK_ADMIN_CHAT_ID }}",
msgtype: "markdown",
markdown: {
content: process.env.MESSAGE,
attachments: [{
callback_id: "help_needed",
actions: [{
name: "help_needed_btn",
text: "Mark as Resolved",
type: "button",
value: "Mark as Resolved",
replace_text: "Already resolved",
border_color: "2c974b",
text_color: "2c974b"
}]
}]
}
}
}));
await Promise.all(p);

0 comments on commit 0abfcc0

Please sign in to comment.