Skip to content

Commit c912034

Browse files
authored
fix(ci): fixes typos and small issues on github scripts (aws-powertools#1302)
1 parent e2863d7 commit c912034

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

.github/scripts/label_pr_based_on_title.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
const { PR_NUMBER, PR_TITLE, AREAS } = require("./constants")
22

33
module.exports = async ({github, context, core}) => {
4-
const FEAT_REGEX = /feat(\((.+)\))?(\:.+)/
5-
const BUG_REGEX = /(fix|bug)(\((.+)\))?(\:.+)/
6-
const DOCS_REGEX = /(docs|doc)(\((.+)\))?(\:.+)/
7-
const CHORE_REGEX = /(chore)(\((.+)\))?(\:.+)/
8-
const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(\:.+)/
9-
const REFACTOR_REGEX = /(refactor)(\((.+)\))?(\:.+)/
4+
const FEAT_REGEX = /feat(\((.+)\))?(:.+)/
5+
const BUG_REGEX = /(fix|bug)(\((.+)\))?(:.+)/
6+
const DOCS_REGEX = /(docs|doc)(\((.+)\))?(:.+)/
7+
const CHORE_REGEX = /(chore)(\((.+)\))?(:.+)/
8+
const DEPRECATED_REGEX = /(deprecated)(\((.+)\))?(:.+)/
9+
const REFACTOR_REGEX = /(refactor)(\((.+)\))?(:.+)/
1010

1111
const labels = {
1212
"feature": FEAT_REGEX,
@@ -22,8 +22,8 @@ module.exports = async ({github, context, core}) => {
2222
try {
2323
for (const label in labels) {
2424
const matcher = new RegExp(labels[label])
25-
const isMatch = matcher.exec(PR_TITLE)
26-
if (isMatch != null) {
25+
const matches = matcher.exec(PR_TITLE)
26+
if (matches != null) {
2727
core.info(`Auto-labeling PR ${PR_NUMBER} with ${label}`)
2828

2929
await github.rest.issues.addLabels({
@@ -54,7 +54,7 @@ module.exports = async ({github, context, core}) => {
5454
}
5555
} finally {
5656
if (miss == Object.keys(labels).length) {
57-
return core.notice(`PR ${PR_NUMBER} title '${PR_TITLE}' doesn't follow semantic titles; skipping...`)
57+
core.notice(`PR ${PR_NUMBER} title '${PR_TITLE}' doesn't follow semantic titles; skipping...`)
5858
}
5959
}
6060
}

.github/scripts/label_related_issue.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ module.exports = async ({github, context, core}) => {
1919

2020
const RELATED_ISSUE_REGEX = /Issue number:[^\d\r\n]+(?<issue>\d+)/;
2121

22+
const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY);
23+
2224
try {
23-
const isMatch = RELATED_ISSUE_REGEX.exec(PR_BODY);
2425
if (!isMatch) {
2526
core.setFailed(`Unable to find related issue for PR number ${PR_NUMBER}.\n\n Body details: ${PR_BODY}`);
2627
return await github.rest.issues.createComment({
@@ -30,11 +31,16 @@ module.exports = async ({github, context, core}) => {
3031
issue_number: PR_NUMBER,
3132
});
3233
}
34+
} catch (error) {
35+
core.setFailed(`Unable to create comment on PR number ${PR_NUMBER}.\n\n Error details: ${error}`);
36+
throw new Error(error);
37+
}
3338

34-
const { groups: {issue} } = isMatch
39+
const { groups: {issue} } = isMatch
3540

41+
try {
3642
core.info(`Auto-labeling related issue ${issue} for release`)
37-
return await github.rest.issues.addLabels({
43+
await github.rest.issues.addLabels({
3844
issue_number: issue,
3945
owner: context.repo.owner,
4046
repo: context.repo.repo,

.github/scripts/save_pr_details.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = async ({github, context, core}) => {
1+
module.exports = async ({context, core}) => {
22
const fs = require('fs');
33
const filename = "pr.txt";
44

@@ -10,4 +10,4 @@ module.exports = async ({github, context, core}) => {
1010
core.setFailed("Failed to save PR details");
1111
console.error(err);
1212
}
13-
}
13+
}

0 commit comments

Comments
 (0)