Skip to content

Commit

Permalink
chore(CI): Add comment when start retrigger obs webhook
Browse files Browse the repository at this point in the history
开始查找并触发webhook时添加评论,这个过程可能比较漫长,因此添加这个提示

log:
  • Loading branch information
hudeng-go committed Oct 31, 2023
1 parent f5a77f5 commit 6ebeccd
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions .github/workflows/chatOps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,36 @@ jobs:
with:
github-token: ${{ steps.get-token.outputs.app_token }}
script: |
const BOT_NAME = "Deepin Obs Bot"
const COMMENT_HEAD = "**" + BOT_NAME + "**\n"
let BODY = "Starting find obs webhook event and retrigger!"
if ( context.issue.number != undefined ) {
const response = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
})
const reg = new RegExp("\\*+" + BOT_NAME + "\\*+")
BotComment= response.data.find(comment => comment.body.match(reg))
if (BotComment) {
await github.rest.issues.deleteComment({
comment_id: BotComment.id,
owner: context.repo.owner,
repo: context.repo.repo,
})
}
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: COMMENT_HEAD + BODY
})
} else {
console.log("context.issue.number is not a valid issue number: " + context.issue.number)
}
const { COMMENT_BODY } = process.env
const checkNameGroup = COMMENT_BODY.match(/\/check (\S+)/)
Expand Down Expand Up @@ -187,15 +217,18 @@ jobs:
core.setOutput('retriggered', "false")
for (var i = 0; i < WebhookDeliveriesResp.data.length; i++) {
let wh = WebhookDeliveriesResp.data[i]
// console.log("webhook event: ", wh.event, ", webhook repository_id: ", wh.repository_id)
if (wh.event == 'pull_request' && wh.repository_id == ${{ github.repository_id }} && (wh.action == 'opened' || wh.action == 'synchronize' || wh.action == 'reopened')) {
console.log("webhook event: ", wh.event, ", webhook repository_id: ", wh.repository_id)
if (wh.event == 'pull_request' && wh.repository_id == ${{ github.repository_id }} && (wh.action == 'opened' || wh.action == 'synchronize')) {
// Get delivery payload and filter
const resp = await github.rest.orgs.getWebhookDelivery({
org: context.repo.owner,
hook_id: process.env.HOOK_ID,
delivery_id: wh.id,
});
if (resp.data.number == context.issue.number) {
//console.log("delivery payload: " + JSON.stringifyesp.data))
console.log("payload number: " + resp.data.request.payload.number)
console.log("pr number: " + context.issue.number)
if (resp.data.request.payload.number == context.issue.number) {
const resp = await github.rest.orgs.redeliverWebhookDelivery({
org: context.repo.owner,
hook_id: process.env.HOOK_ID,
Expand All @@ -220,7 +253,7 @@ jobs:
github-token: ${{ steps.get-token.outputs.app_token }}
script: |
console.log("redeliveried failed, context.issue.number: ", context.issue.number)
const BOT_NAME = "Deepin CatGPT Bot"
const BOT_NAME = "Deepin Obs Bot"
const COMMENT_HEAD = "**" + BOT_NAME + "**\n"
let COMMENT_BODY = "Deepin redeliveried failed, need update or recreate pull request!!!"
Expand Down

0 comments on commit 6ebeccd

Please sign in to comment.