Skip to content

Commit a9e11ec

Browse files
Eli Skeggsskeggse
authored andcommitted
fix: fix control flow + github auth error case
As was foretold, this immediately became problematic and unmaintainable as it caused dependabot to merge PRs when it shouldn't due to a `catch` case not re-throwing.
1 parent 4b68388 commit a9e11ec

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

src/index.js

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ async function lintPR() {
8181
// Prevent unhandled rejections.
8282
squashCommitPromise.catch(() => {});
8383

84+
let branchCommitlintOutput;
8485
try {
8586
// TODO(Eli): Check for allow_merge_commit || allow_rebase_merge on the GitHub repository if
8687
// accessible.
@@ -94,42 +95,42 @@ async function lintPR() {
9495
throw err;
9596
}
9697

97-
try {
98-
const rawSquashCommit = await squashCommitPromise;
99-
try {
100-
await execa(COMMITLINT || commitlint, [], {
101-
input: rawSquashCommit,
102-
all: true,
103-
});
104-
console.log(`squash commit for ${TARGET_BRANCH} passed linter`);
105-
} catch (errSquash) {
106-
if (errSquash.code === 'ENOGITHUBAUTH') {
107-
console.error('Unable to determine whether the squash commit would be valid');
108-
console.error(errSquash);
109-
}
110-
console.error(
111-
'Neither the commits in the pull request nor the pull request description are valid according to commitlint'
112-
);
113-
console.error('Errors found with squash commit');
114-
console.group();
115-
console.error(errSquash.all);
116-
console.groupEnd();
117-
console.error('Errors found in branch commits');
118-
console.group();
119-
console.error(err.all);
120-
console.groupEnd();
121-
throw errSquash;
122-
}
123-
} catch (errSquash) {
124-
if (errSquash.code === 'ENOGITHUBAUTH') {
125-
console.error('Unable to determine whether the squash commit would be valid');
126-
console.error(errSquash);
127-
console.error();
128-
console.error(err.all);
129-
} else {
130-
throw errSquash;
131-
}
98+
branchCommitlintOutput = err.all;
99+
}
100+
101+
let rawSquashCommit;
102+
try {
103+
rawSquashCommit = await squashCommitPromise;
104+
} catch (err) {
105+
if (err.code === 'ENOGITHUBAUTH') {
106+
console.error('Unable to determine whether the squash commit would be valid');
107+
console.error(err);
108+
console.error();
109+
console.error(branchCommitlintOutput);
132110
}
111+
throw err;
112+
}
113+
114+
try {
115+
await execa(COMMITLINT || commitlint, [], {
116+
input: rawSquashCommit,
117+
all: true,
118+
});
119+
console.log(`squash commit for ${TARGET_BRANCH} passed linter`);
120+
return;
121+
} catch (err) {
122+
console.error(
123+
'Neither the commits in the pull request nor the pull request description are valid according to commitlint'
124+
);
125+
console.error('Errors found with squash commit');
126+
console.group();
127+
console.error(err.all);
128+
console.groupEnd();
129+
console.error('Errors found in branch commits');
130+
console.group();
131+
console.error(branchCommitlintOutput);
132+
console.groupEnd();
133+
throw err;
133134
}
134135
}
135136

0 commit comments

Comments
 (0)