Skip to content

Commit 16b438c

Browse files
committed
Add automatic DCO Check failure notification action.
The check itself comes from the DCO Check GitHub app. These apps are tied directly to GitHub which is why the `app_id` is a known constant. It's the same id regardless of the repository it monitors. These were forked from MLFlow's public repository: https: //github.com/mlflow/mlflow/blob/master/.github/workflows/notify-dco-failure.js Signed-off-by: Jesse Whitehouse <[email protected]>
1 parent 416acc4 commit 16b438c

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module.exports = async ({ context, github }) => {
2+
const { owner, repo } = context.repo;
3+
const { number: issue_number } = context.issue;
4+
const ref = context.payload.pull_request.head.sha;
5+
const { user } = context.payload.pull_request;
6+
7+
function sleep(ms) {
8+
return new Promise(resolve => setTimeout(resolve, ms));
9+
}
10+
11+
async function getDcoCheck() {
12+
const backoffs = [0, 2, 4, 6, 8];
13+
const numAttempts = backoffs.length;
14+
for (const [index, backoff] of backoffs.entries()) {
15+
await sleep(backoff * 1000);
16+
const resp = await github.checks.listForRef({
17+
owner,
18+
repo,
19+
ref,
20+
app_id: 1861, // ID of the DCO check app
21+
});
22+
23+
const { check_runs } = resp.data;
24+
if (check_runs.length > 0 && check_runs[0].status === "completed") {
25+
return check_runs[0];
26+
}
27+
console.log(
28+
`[Attempt ${index + 1}/${numAttempts}]`,
29+
"The DCO check hasn't completed yet."
30+
);
31+
}
32+
}
33+
34+
const dcoCheck = await getDcoCheck();
35+
if (dcoCheck.conclusion !== "success") {
36+
const body = [
37+
`@${user.login} Thanks for the contribution! The DCO check failed. `,
38+
`Please sign off your commits by following the instructions here: ${dcoCheck.html_url}. `,
39+
"See https://github.com/databricks/databricks-sql-python/blob/main/CONTRIBUTING.md#sign-your-work for more ",
40+
"details.",
41+
].join("");
42+
await github.issues.createComment({
43+
owner,
44+
repo,
45+
issue_number,
46+
body,
47+
});
48+
}
49+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Notify DCO Failure
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
8+
jobs:
9+
notify:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
with:
14+
submodules: recursive
15+
- uses: actions/github-script@v4
16+
with:
17+
script: |
18+
const script = require(
19+
`${process.env.GITHUB_WORKSPACE}/.github/workflows/notify-dco-failure.js`
20+
);
21+
script({ context, github });

0 commit comments

Comments
 (0)