Skip to content

Commit 696aa08

Browse files
api-clients-generation-pipeline[bot]zippolyteci.datadog-api-spec
authored
Enable automatic merge of generated PRs (#475)
* Add workflow for PR approved * Regenerate client from commit 6fd1064 of spec repo Co-authored-by: Hippolyte HENRY <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent 667da19 commit 696aa08

File tree

3 files changed

+82
-4
lines changed

3 files changed

+82
-4
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.4.1.dev8",
7-
"regenerated": "2021-06-07 11:36:18.870170",
8-
"spec_repo_commit": "cb48df5"
7+
"regenerated": "2021-06-08 12:35:42.764856",
8+
"spec_repo_commit": "6fd1064"
99
},
1010
"v2": {
1111
"apigentools_version": "1.4.1.dev8",
12-
"regenerated": "2021-06-07 11:36:46.868127",
13-
"spec_repo_commit": "cb48df5"
12+
"regenerated": "2021-06-08 12:36:09.047977",
13+
"spec_repo_commit": "6fd1064"
1414
}
1515
}
1616
}

.github/workflows/approved_status.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Send PR Approval Status
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
types: ["review_requested", "synchronize", "opened", "reopened"]
8+
pull_request_review:
9+
types:
10+
- submitted
11+
- dismissed
12+
13+
jobs:
14+
send_status:
15+
runs-on: ubuntu-latest
16+
if: >
17+
github.event.pull_request.draft == false &&
18+
!contains(github.event.pull_request.labels.*.name, 'ci/skip') &&
19+
!contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')
20+
steps:
21+
- name: Get GitHub App token
22+
id: get_token
23+
uses: tibdex/[email protected]
24+
with:
25+
app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
26+
private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
27+
repository: DataDog/datadog-api-spec
28+
- name: Checkout code
29+
uses: actions/checkout@v2
30+
- name: Post PR review status check
31+
uses: actions/[email protected]
32+
with:
33+
github-token: ${{ steps.get_token.outputs.token }}
34+
script: |
35+
const script = require('.github/workflows/scripts/approved_status.js')
36+
await script.post_approved_pr_status_check(github, context)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const SPEC_REPO = "datadog-api-spec"
2+
3+
module.exports.post_approved_pr_status_check = async (github, context) => {
4+
const pr_num = context.payload.pull_request.head.ref.split("/")[2]
5+
const {data: pr} = await github.pulls.get({
6+
owner: context.repo.owner,
7+
repo: SPEC_REPO,
8+
pull_number: pr_num,
9+
});
10+
let status = "pending"
11+
if (context.eventName === "pull_request_review" && context.payload.action === "submitted") {
12+
if (context.payload.review.state === "approved") {
13+
status = "success"
14+
} else if (context.payload.review.state === "changes_requested") {
15+
status = "failure"
16+
}
17+
} else {
18+
const pr_id = context.payload.pull_request.node_id
19+
const query = `{
20+
node(id: "${pr_id}") {
21+
... on PullRequest {
22+
reviewDecision
23+
}
24+
}
25+
}`
26+
const { node: { reviewDecision: review } } = await github.graphql(query, {})
27+
if (review === "APPROVED") {
28+
status = "success"
29+
} else if (review === "CHANGES_REQUESTED") {
30+
status = "failure"
31+
}
32+
}
33+
await github.repos.createCommitStatus({
34+
owner: context.repo.owner,
35+
repo: SPEC_REPO,
36+
sha: pr.head.sha,
37+
state: status,
38+
target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/pull/${context.payload.pull_request.number}`,
39+
description: `PR on ${context.repo.repo} has been approved`,
40+
context: `${context.repo.repo}_pr_approved`
41+
});
42+
}

0 commit comments

Comments
 (0)