Skip to content

Commit

Permalink
fix: fix baseRef issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Aug 2, 2024
1 parent 695bbde commit 60d37f8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ async function run() {
info(`Branch: \x1b[34m${branch}\x1b[0m`);
}

info(`Ref: baseRef(\x1b[32m${baseRef}\x1b[0m), options.headRef(\x1b[32m${headRef}\x1b[0m), tagRef(\x1b[32m${options.tagRef}\x1b[0m)`);
info(`Ref: baseRef(\x1b[32m${options.baseRef}\x1b[0m), options.headRef(\x1b[32m${headRef}\x1b[0m), tagRef(\x1b[32m${options.tagRef}\x1b[0m)`);

await handleBranchData(options);

if ((baseRef || '').replace(/^[vV]/, '') === headRef) {
setOutput('tag', baseRef);
setOutput('version', baseRef.replace(/^[vV]/, ''));
info(`Done: baseRef(\x1b[33m${baseRef}\x1b[0m) === headRef(\x1b[32m${headRef}\x1b[0m)`);
if ((options.baseRef || '').replace(/^[vV]/, '') === headRef) {
setOutput('tag', options.baseRef);
setOutput('version', options.baseRef.replace(/^[vV]/, ''));
info(`Done: options.baseRef(\x1b[33m${options.baseRef}\x1b[0m) === headRef(\x1b[32m${headRef}\x1b[0m)`);
return;
}

if (regexp.test(headRef) && regexp.test(baseRef)) {
if (regexp.test(headRef) && regexp.test(options.baseRef)) {
const resultData = await fetchCommits(options);
const commitLog = processCommits(resultData, options);

Expand All @@ -58,8 +58,8 @@ async function run() {

info(`Tag: \x1b[34m${tagRef || headRef || '-'}\x1b[0m`);
info(`Input head-ref: \x1b[34m${headRef}\x1b[0m`);
info(`Input base-ref: \x1b[34m${baseRef}\x1b[0m`);
setOutput('compareurl', `/~https://github.com/${owner}/${repo}/compare/${baseRef}...${tagRef || headRef}`);
info(`Input base-ref: \x1b[34m${options.baseRef}\x1b[0m`);
setOutput('compareurl', `/~https://github.com/${owner}/${repo}/compare/${options.baseRef}...${tagRef || headRef}`);
setOutput('version', getVersion(tagRef || headRef || '').replace(/^v/, ''));
} else {
setFailed('Branch names must contain only numbers, strings, underscores, periods, and dashes.');
Expand Down
11 changes: 7 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,17 @@ export const parseCustomEmojis = (customEmoji: string, defaultTypes: Record<stri

export const handleNoBaseRef = async (options: ActionOptions) => {
const { octokit, owner, repo } = options;
// Get the latest release
const latestRelease = await octokit.rest.repos.getLatestRelease({ ...context.repo });
if (latestRelease.status !== 200) {
setFailed(`There are no releases on ${owner}/${repo}. Tags are not releases. (status=${latestRelease.status}) ${(latestRelease.data as any).message || ''}`);
} else {
options.baseRef = latestRelease.data.tag_name;
startGroup(`Latest Release Result Data: \x1b[32m${latestRelease.status || '-'}\x1b[0m \x1b[32m${latestRelease.data.tag_name}\x1b[0m`);
info(`${JSON.stringify(latestRelease, null, 2)}`);
endGroup();
return latestRelease.data.tag_name;
}
options.baseRef = latestRelease.data.tag_name;
startGroup(`Latest Release Result Data: \x1b[32m${latestRelease.status || '-'}\x1b[0m \x1b[32m${latestRelease.data.tag_name}\x1b[0m`);
info(`${JSON.stringify(latestRelease, null, 2)}`);
endGroup();
};

export const handleBranchData = async (options: ActionOptions) => {
Expand Down

0 comments on commit 60d37f8

Please sign in to comment.