mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-05-10 18:44:19 +00:00
Fix updating an existing draft release
Don't just return the release without doing anything else, notably this didn't allow updating an existing draft release body. This change required refactoring the code to use a new helper find_existing_release() function, but the only effective change is that the main release() function doesn't return early any more if a draft release already exists. This commit is best viewed ignoring whitespace-only changes and using git --color-moved option.
This commit is contained in:
parent
9414f126fb
commit
4c1f6af6e1
2 changed files with 83 additions and 67 deletions
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
|
@ -179,6 +179,50 @@ export const upload = async (
|
||||||
return json;
|
return json;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const find_existing_release = async (
|
||||||
|
config: Config,
|
||||||
|
releaser: Releaser,
|
||||||
|
tag: string
|
||||||
|
): Promise<Release | null> => {
|
||||||
|
const [owner, repo] = config.github_repository.split("/");
|
||||||
|
|
||||||
|
// you can't get a an existing draft by tag
|
||||||
|
// so we must find one in the list of all releases
|
||||||
|
if (config.input_draft) {
|
||||||
|
for await (const response of releaser.allReleases({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
})) {
|
||||||
|
let release = response.data.find(
|
||||||
|
(release) => release.name === config.input_name
|
||||||
|
);
|
||||||
|
if (release) {
|
||||||
|
return release;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
let existingRelease = await releaser.getReleaseByTag({
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
tag,
|
||||||
|
});
|
||||||
|
return existingRelease.data;
|
||||||
|
} catch (error) {
|
||||||
|
if (error.status === 404) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
console.log(
|
||||||
|
`⚠️ Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`
|
||||||
|
);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
export const release = async (
|
export const release = async (
|
||||||
config: Config,
|
config: Config,
|
||||||
releaser: Releaser,
|
releaser: Releaser,
|
||||||
|
@ -198,30 +242,9 @@ export const release = async (
|
||||||
|
|
||||||
const discussion_category_name = config.input_discussion_category_name;
|
const discussion_category_name = config.input_discussion_category_name;
|
||||||
const generate_release_notes = config.input_generate_release_notes;
|
const generate_release_notes = config.input_generate_release_notes;
|
||||||
try {
|
|
||||||
// you can't get a an existing draft by tag
|
|
||||||
// so we must find one in the list of all releases
|
|
||||||
if (config.input_draft) {
|
|
||||||
for await (const response of releaser.allReleases({
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
})) {
|
|
||||||
let release = response.data.find(
|
|
||||||
(release) => release.name === config.input_name
|
|
||||||
);
|
|
||||||
if (release) {
|
|
||||||
return release;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let existingRelease = (
|
|
||||||
await releaser.getReleaseByTag({
|
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
tag,
|
|
||||||
})
|
|
||||||
).data;
|
|
||||||
|
|
||||||
|
const existingRelease = await find_existing_release(config, releaser, tag);
|
||||||
|
if (existingRelease !== null) {
|
||||||
const release_id = existingRelease.id;
|
const release_id = existingRelease.id;
|
||||||
let target_commitish: string;
|
let target_commitish: string;
|
||||||
if (
|
if (
|
||||||
|
@ -274,8 +297,7 @@ export const release = async (
|
||||||
generate_release_notes,
|
generate_release_notes,
|
||||||
});
|
});
|
||||||
return release.data;
|
return release.data;
|
||||||
} catch (error) {
|
} else {
|
||||||
if (error.status === 404) {
|
|
||||||
const tag_name = tag;
|
const tag_name = tag;
|
||||||
const name = config.input_name || tag;
|
const name = config.input_name || tag;
|
||||||
const body = releaseBody(config);
|
const body = releaseBody(config);
|
||||||
|
@ -314,11 +336,5 @@ export const release = async (
|
||||||
);
|
);
|
||||||
return release(config, releaser, maxRetries - 1);
|
return release(config, releaser, maxRetries - 1);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
console.log(
|
|
||||||
`⚠️ Unexpected error fetching GitHub release for tag ${config.github_ref}: ${error}`
|
|
||||||
);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue