mirror of
https://github.com/softprops/action-gh-release.git
synced 2025-05-11 02:44:20 +00:00
add tests for finding tag from releases
add tests for updated functionality to break when we find a release. the logic has been extracted into its own function, to make testing simpler by avoiding over mocking/stubbing of network calls that would create or update a release. the tests that were added use jest's describe/it blocks, but use node's assert function to align with other tests. there isn't any prior art for mocking function calls in the codebase, so for now we use simple promises in "mock" objects that adhere to the Releaser interface
This commit is contained in:
parent
f84ee9b913
commit
b585fed8fa
3 changed files with 290 additions and 14 deletions
|
@ -229,16 +229,7 @@ export const release = async (
|
|||
// so we must find one in the list of all releases
|
||||
let _release: Release | undefined = undefined;
|
||||
if (config.input_draft) {
|
||||
for await (const response of releaser.allReleases({
|
||||
owner,
|
||||
repo,
|
||||
})) {
|
||||
_release = response.data.find((release) => release.tag_name === tag);
|
||||
// detect if we found a release - note that a draft release tag may be an empty string
|
||||
if (typeof _release !== "undefined") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
_release = await findTagFromReleases(releaser, owner, repo, tag);
|
||||
} else {
|
||||
_release = (
|
||||
await releaser.getReleaseByTag({
|
||||
|
@ -342,6 +333,35 @@ export const release = async (
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Finds a release by tag name from all a repository's releases.
|
||||
*
|
||||
* @param releaser - The GitHub API wrapper for release operations
|
||||
* @param owner - The owner of the repository
|
||||
* @param repo - The name of the repository
|
||||
* @param tag - The tag name to search for
|
||||
* @returns The release with the given tag name, or undefined if no release with that tag name is found
|
||||
*/
|
||||
export async function findTagFromReleases(
|
||||
releaser: Releaser,
|
||||
owner: string,
|
||||
repo: string,
|
||||
tag: string,
|
||||
) {
|
||||
let _release: Release | undefined;
|
||||
for await (const response of releaser.allReleases({
|
||||
owner,
|
||||
repo,
|
||||
})) {
|
||||
_release = response.data.find((release) => release.tag_name === tag);
|
||||
// detect if we found a release - note that a draft release tag may be an empty string
|
||||
if (typeof _release !== "undefined") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return _release;
|
||||
}
|
||||
|
||||
async function createRelease(
|
||||
tag: string,
|
||||
config: Config,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue