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

Allow updating draft releases #245

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

38 changes: 22 additions & 16 deletions src/github.ts
Expand Up @@ -199,47 +199,53 @@ export const release = async (
const discussion_category_name = config.input_discussion_category_name;
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
let existingRelease: Release = {} as Release;

if (config.input_draft) {
// you can't get a an existing draft by tag
// so we must find one in the list of all releases
for await (const response of releaser.allReleases({
owner,
repo
})) {
let release = response.data.find(release => release.tag_name === tag);
if (release) {
return release;
existingRelease = release;
break;
}
}
} else {
existingRelease = (
await releaser.getReleaseByTag({
owner,
repo,
tag
})
).data;
}
let existingRelease = await releaser.getReleaseByTag({
owner,
repo,
tag
});

const release_id = existingRelease.data.id;
const release_id = existingRelease.id;
let target_commitish: string;
if (
config.input_target_commitish &&
config.input_target_commitish !== existingRelease.data.target_commitish
config.input_target_commitish !== existingRelease.target_commitish
) {
console.log(
`Updating commit from "${existingRelease.data.target_commitish}" to "${config.input_target_commitish}"`
`Updating commit from "${existingRelease.target_commitish}" to "${config.input_target_commitish}"`
);
target_commitish = config.input_target_commitish;
} else {
target_commitish = existingRelease.data.target_commitish;
target_commitish = existingRelease.target_commitish;
}

const tag_name = tag;
const name = config.input_name || existingRelease.data.name || tag;
const name = config.input_name || existingRelease.name || tag;
// revisit: support a new body-concat-strategy input for accumulating
// body parts as a release gets updated. some users will likely want this while
// others won't previously this was duplicating content for most which
// no one wants
const workflowBody = releaseBody(config) || "";
const existingReleaseBody = existingRelease.data.body || "";
const existingReleaseBody = existingRelease.body || "";
let body: string;
if (config.input_append_body && workflowBody && existingReleaseBody) {
body = existingReleaseBody + "\n" + workflowBody;
Expand All @@ -250,11 +256,11 @@ export const release = async (
const draft =
config.input_draft !== undefined
? config.input_draft
: existingRelease.data.draft;
: existingRelease.draft;
const prerelease =
config.input_prerelease !== undefined
? config.input_prerelease
: existingRelease.data.prerelease;
: existingRelease.prerelease;

const release = await releaser.updateRelease({
owner,
Expand Down