Skip to content

Commit dcd2715

Browse files
David MurphyDavid Murphy
David Murphy
authored and
David Murphy
committed
feat(close-pr-support): Enable commit detection when tag search fails by failing back to looking at commits in closed & merged PR
1 parent dbd80d2 commit dcd2715

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

src/action.ts

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export default async function main() {
122122
core.setOutput('previous_tag', previousTag.name);
123123

124124
commits = await getCommits(previousTag.commit.sha, commitRef);
125+
core.debug("We found "+ commits.length +" commits to consider!");
125126

126127
let bump = await analyzeCommits(
127128
{

src/utils.ts

+45-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import DEFAULT_RELEASE_TYPES from '@semantic-release/commit-analyzer/lib/default
55
import { compareCommits, listTags } from './github';
66
import { defaultChangelogRules } from './defaults';
77
import { Await } from './ts';
8+
import {context} from "@actions/github";
89

910
type Tags = Await<ReturnType<typeof listTags>>;
1011

@@ -30,19 +31,53 @@ export async function getValidTags(
3031

3132
return validTags;
3233
}
34+
interface FinalCommit {
35+
sha: string | null;
36+
commit: {
37+
message: string;
38+
}
39+
}
40+
3341

3442
export async function getCommits(
35-
baseRef: string,
36-
headRef: string
43+
baseRef: string,
44+
headRef: string
3745
): Promise<{ message: string; hash: string | null }[]> {
38-
const commits = await compareCommits(baseRef, headRef);
39-
40-
return commits
41-
.filter((commit) => !!commit.commit.message)
42-
.map((commit) => ({
43-
message: commit.commit.message,
44-
hash: commit.sha,
45-
}));
46+
let commits: Array<FinalCommit>;
47+
commits = await compareCommits(baseRef, headRef);
48+
core.info("We found " + commits.length + " commits using classic compare!")
49+
if (commits.length < 1) {
50+
core.info("We did not find enough commits, attempting to scan closed PR method.")
51+
commits = getClosedPRCommits();
52+
}
53+
if (commits.length == 0) {
54+
return []
55+
}
56+
57+
return commits
58+
.filter((commit: FinalCommit) => !!commit.commit.message)
59+
.map((commit: FinalCommit) => ({
60+
message: commit.commit.message,
61+
hash: commit.sha,
62+
}))
63+
}
64+
65+
function getClosedPRCommits(){
66+
let commits = Array<FinalCommit>();
67+
if( !('pull_request' in context.payload)){
68+
core.debug("We are in a closed PR context continuing.");
69+
core.debug(JSON.stringify(context.payload.commits))
70+
let pr_commit_count = context.payload.commits.length
71+
core.info("We found "+pr_commit_count+" commits from the Closed PR method.")
72+
commits = context.payload.commits
73+
.filter((commit: FinalCommit) => !!commit.commit.message)
74+
.filter((commit: FinalCommit) => ({
75+
message: commit.commit.message,
76+
hash: commit.sha,
77+
}));
78+
core.debug("After processing we are going to present " + commits.length + " commits!")
79+
}
80+
return commits;
4681
}
4782

4883
export function getBranchFromRef(ref: string) {

0 commit comments

Comments
 (0)