Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable backup commit detection #153

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default async function main() {
core.setOutput('previous_tag', previousTag.name);

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

let bump = await analyzeCommits(
{
Expand Down
46 changes: 43 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import DEFAULT_RELEASE_TYPES from '@semantic-release/commit-analyzer/lib/default
import { compareCommits, listTags } from './github';
import { defaultChangelogRules } from './defaults';
import { Await } from './ts';
import { context } from '@actions/github';

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

Expand All @@ -30,21 +31,60 @@ export async function getValidTags(

return validTags;
}
interface FinalCommit {
sha: string | null;
commit: {
message: string;
};
}

export async function getCommits(
baseRef: string,
headRef: string
): Promise<{ message: string; hash: string | null }[]> {
const commits = await compareCommits(baseRef, headRef);
let commits: Array<FinalCommit>;
commits = await compareCommits(baseRef, headRef);
core.info('We found ' + commits.length + ' commits using classic compare!');
if (commits.length < 1) {
core.info(
'We did not find enough commits, attempting to scan closed PR method.'
);
commits = getClosedPRCommits();
}
if (commits.length == 0) {
return [];
}

return commits
.filter((commit) => !!commit.commit.message)
.map((commit) => ({
.filter((commit: FinalCommit) => !!commit.commit.message)
.map((commit: FinalCommit) => ({
message: commit.commit.message,
hash: commit.sha,
}));
}

function getClosedPRCommits() {
let commits = Array<FinalCommit>();
if (!('pull_request' in context.payload)) {
core.debug('We are in a closed PR context continuing.');
core.debug(JSON.stringify(context.payload.commits));
let pr_commit_count = context.payload.commits.length;
core.info(
'We found ' + pr_commit_count + ' commits from the Closed PR method.'
);
commits = context.payload.commits
.filter((commit: FinalCommit) => !!commit.commit.message)
.filter((commit: FinalCommit) => ({
message: commit.commit.message,
hash: commit.sha,
}));
core.debug(
'After processing we are going to present ' + commits.length + ' commits!'
);
}
return commits;
}

export function getBranchFromRef(ref: string) {
return ref.replace('refs/heads/', '');
}
Expand Down