-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig-diff-post-comment.js
More file actions
120 lines (101 loc) · 3.83 KB
/
config-diff-post-comment.js
File metadata and controls
120 lines (101 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
module.exports = async ({ github, context, core, configDiff }) => {
try {
const { owner, repo } = context.repo;
const issueNumber = context.payload.pull_request.number;
// List all the comments
const comments = await github.paginate(
github.rest.issues.listComments, {
owner,
repo,
issue_number: issueNumber,
per_page: 100,
}
);
// Check if any comment contains `/config check ok`
const configCheckOkComment = comments.find(
comment => comment.body.includes("/config check ok") && !comment.body.includes("### Config Diff Tool Output")
);
if (configCheckOkComment) {
core.info("Found '/config check ok' comment. Returning with success.");
return;
}
const existingComment = comments.find(comment => comment.body.includes("### Config Diff Tool Output"));
// Do not create comment if there are no configuration changes
if (!configDiff) {
core.info("No changes detected. Skipping comment creation.");
if (existingComment){
// Remove any outdated configuration diff comments
core.info("Existing config diff comment found. Deleting it...");
await github.rest.issues.deleteComment({
comment_id: existingComment.id,
owner,
repo,
});
}
return;
}
const commentBody = `
### Config Diff Tool Output
\`\`\`diff
${configDiff}
\`\`\`
The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.
Ignore this comment if docs are already updated. To make the "Check ceph config changes" CI check pass, please comment \`/config check ok\` and re-run the test. `;
// List all files in the pull request
core.info("Fetching list of files changed in the pull request...");
const files = await github.paginate(
github.rest.pulls.listFiles,
{
owner,
repo,
pull_number: issueNumber,
per_page: 100,
}
);
// Annotate YAML files
files.forEach(file => {
// Only annotate the `yaml.in` files present in `src/common/options` folder
if (file.filename.endsWith(".yaml.in") && file.filename.startsWith("src/common/options/")) {
core.info(`Annotating file: ${file.filename}`);
// Show annotations only at the start of the file
core.notice(
`Configuration changes detected in ${file.filename}. Please update the release documentation if necessary. Ignore if already done`,
{
title: "Configuration Change Detected",
file: file.filename,
startLine: 1,
endLine: 1,
}
);
}
});
core.summary.addRaw(commentBody);
await core.summary.write()
if (existingComment) {
// There might have been new configuration changes made after posting
// the first comment. Hence replace the old comment with the new updated
// changes
core.info("A config diff comment already exists, updating it...");
// Update the existing comment
await github.rest.issues.updateComment ({
comment_id: existingComment.id,
owner,
repo,
body: commentBody,
});
} else {
core.info("Creating a new config diff comment...");
// Create a new comment
await github.rest.issues.createComment({
issue_number: issueNumber,
owner,
repo,
body: commentBody,
});
}
// Set the status as FAILED if any configuration changes are detected
core.setFailed("Configuration Changes Detected, Update release documents - if necessary");
} catch (error) {
core.setFailed(error.message);
}
}