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

Support auto generating release notes #179

Merged
merged 1 commit into from
Nov 7, 2021
Merged
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ The following are optional as `step.with` keys
| `target_commitish` | String | Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA. |
| `token` | String | Secret GitHub Personal Access Token. Defaults to `${{ github.token }}` |
| `discussion_category_name` | String | If specified, a discussion of the specified category is created and linked to the release. The value must be a category that already exists in the repository. For more information, see ["Managing categories for discussions in your repository."](https://docs.github.com/en/discussions/managing-discussions-for-your-community/managing-categories-for-discussions-in-your-repository) |
| `generate_release_notes` | Boolean | Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise, a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes. |

💡 When providing a `body` and `body_path` at the same time, `body_path` will be
attempted first, then falling back on `body` if the path can not be read from.
Expand Down
52 changes: 43 additions & 9 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ describe("util", () => {
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined,
input_discussion_category_name: undefined
input_discussion_category_name: undefined,
input_generate_release_notes: false
})
);
});
Expand All @@ -69,7 +70,8 @@ describe("util", () => {
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined,
input_discussion_category_name: undefined
input_discussion_category_name: undefined,
input_generate_release_notes: false
})
);
});
Expand All @@ -88,7 +90,8 @@ describe("util", () => {
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined,
input_discussion_category_name: undefined
input_discussion_category_name: undefined,
input_generate_release_notes: false
})
);
});
Expand Down Expand Up @@ -119,7 +122,8 @@ describe("util", () => {
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined
input_discussion_category_name: undefined,
input_generate_release_notes: false
}
);
});
Expand All @@ -142,7 +146,8 @@ describe("util", () => {
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: "affa18ef97bc9db20076945705aba8c516139abd",
input_discussion_category_name: undefined
input_discussion_category_name: undefined,
input_generate_release_notes: false
}
);
});
Expand All @@ -164,10 +169,36 @@ describe("util", () => {
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined,
input_discussion_category_name: "releases"
input_discussion_category_name: "releases",
input_generate_release_notes: false
}
);
});

it("supports generating release notes", () => {
assert.deepStrictEqual(
parseConfig({
INPUT_GENERATE_RELEASE_NOTES: "true"
}),
{
github_ref: "",
github_repository: "",
github_token: "",
input_body: undefined,
input_body_path: undefined,
input_draft: undefined,
input_prerelease: undefined,
input_files: [],
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined,
input_generate_release_notes: true
}
);
});

it("prefers GITHUB_TOKEN over token input for backwards compatibility", () => {
assert.deepStrictEqual(
parseConfig({
Expand All @@ -189,7 +220,8 @@ describe("util", () => {
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined
input_discussion_category_name: undefined,
input_generate_release_notes: false
}
);
});
Expand All @@ -213,7 +245,8 @@ describe("util", () => {
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined
input_discussion_category_name: undefined,
input_generate_release_notes: false
}
);
});
Expand All @@ -236,7 +269,8 @@ describe("util", () => {
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined,
input_discussion_category_name: undefined
input_discussion_category_name: undefined,
input_generate_release_notes: false
}
);
});
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ inputs:
discussion_category_name:
description: "If specified, a discussion of the specified category is created and linked to the release. The value must be a category that already exists in the repository. If there is already a discussion linked to the release, this parameter is ignored."
required: false
generate_release_notes:
description: "Whether to automatically generate the name and body for this release. If name is specified, the specified name will be used; otherwise, a name will be automatically generated. If body is specified, the body will be pre-pended to the automatically generated notes."
required: false
env:
"GITHUB_TOKEN": "As provided by Github Actions"
outputs:
Expand Down
11 changes: 9 additions & 2 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface Releaser {
prerelease: boolean | undefined;
target_commitish: string | undefined;
discussion_category_name: string | undefined;
generate_release_notes: boolean | undefined;
}): Promise<{ data: Release }>;

updateRelease(params: {
Expand All @@ -57,6 +58,7 @@ export interface Releaser {
draft: boolean | undefined;
prerelease: boolean | undefined;
discussion_category_name: string | undefined;
generate_release_notes: boolean | undefined;
}): Promise<{ data: Release }>;

allReleases(params: {
Expand Down Expand Up @@ -89,6 +91,7 @@ export class GitHubReleaser implements Releaser {
prerelease: boolean | undefined;
target_commitish: string | undefined;
discussion_category_name: string | undefined;
generate_release_notes: boolean | undefined;
}): Promise<{ data: Release }> {
return this.github.rest.repos.createRelease(params);
}
Expand All @@ -104,6 +107,7 @@ export class GitHubReleaser implements Releaser {
draft: boolean | undefined;
prerelease: boolean | undefined;
discussion_category_name: string | undefined;
generate_release_notes: boolean | undefined;
}): Promise<{ data: Release }> {
return this.github.rest.repos.updateRelease(params);
}
Expand Down Expand Up @@ -193,6 +197,7 @@ 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
Expand Down Expand Up @@ -254,7 +259,8 @@ export const release = async (
body,
draft,
prerelease,
discussion_category_name
discussion_category_name,
generate_release_notes
});
return release.data;
} catch (error) {
Expand Down Expand Up @@ -282,7 +288,8 @@ export const release = async (
draft,
prerelease,
target_commitish,
discussion_category_name
discussion_category_name,
generate_release_notes
});
return release.data;
} catch (error) {
Expand Down
4 changes: 3 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface Config {
input_fail_on_unmatched_files?: boolean;
input_target_commitish?: string;
input_discussion_category_name?: string;
input_generate_release_notes?: boolean;
}

export const uploadUrl = (url: string): string => {
Expand Down Expand Up @@ -65,7 +66,8 @@ export const parseConfig = (env: Env): Config => {
input_fail_on_unmatched_files: env.INPUT_FAIL_ON_UNMATCHED_FILES == "true",
input_target_commitish: env.INPUT_TARGET_COMMITISH || undefined,
input_discussion_category_name:
env.INPUT_DISCUSSION_CATEGORY_NAME || undefined
env.INPUT_DISCUSSION_CATEGORY_NAME || undefined,
input_generate_release_notes: env.INPUT_GENERATE_RELEASE_NOTES == "true"
};
};

Expand Down