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 linking to discussions #136

Merged
merged 3 commits into from
Aug 8, 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
46 changes: 38 additions & 8 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ describe("util", () => {
input_files: [],
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined
input_target_commitish: undefined,
input_discussion_category_name: undefined
})
);
});
Expand All @@ -67,7 +68,8 @@ describe("util", () => {
input_files: [],
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined
input_target_commitish: undefined,
input_discussion_category_name: undefined
})
);
});
Expand All @@ -85,7 +87,8 @@ describe("util", () => {
input_files: [],
input_name: undefined,
input_tag_name: undefined,
input_target_commitish: undefined
input_target_commitish: undefined,
input_discussion_category_name: undefined
})
);
});
Expand All @@ -104,7 +107,8 @@ describe("util", () => {
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined
input_target_commitish: undefined,
input_discussion_category_name: undefined
});
});

Expand All @@ -125,7 +129,30 @@ describe("util", () => {
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: "affa18ef97bc9db20076945705aba8c516139abd"
input_target_commitish: "affa18ef97bc9db20076945705aba8c516139abd",
input_discussion_category_name: undefined
}
);
});
it("supports discussion category names", () => {
assert.deepStrictEqual(
parseConfig({
INPUT_DISCUSSION_CATEGORY_NAME: "releases"
}),
{
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: "releases"
}
);
});
Expand All @@ -149,7 +176,8 @@ describe("util", () => {
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined
input_target_commitish: undefined,
input_discussion_category_name: undefined
}
);
});
Expand All @@ -172,7 +200,8 @@ describe("util", () => {
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined
input_target_commitish: undefined,
input_discussion_category_name: undefined
}
);
});
Expand All @@ -194,7 +223,8 @@ describe("util", () => {
input_name: undefined,
input_tag_name: undefined,
input_fail_on_unmatched_files: false,
input_target_commitish: undefined
input_target_commitish: undefined,
input_discussion_category_name: undefined
}
);
});
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ inputs:
target_commitish:
description: "Commitish value that determines where the Git tag is created from. Can be any branch or commit SHA."
required: false
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
env:
"GITHUB_TOKEN": "As provided by Github Actions"
outputs:
url:
description: 'URL to the Release HTML Page'
description: "URL to the Release HTML Page"
id:
description: 'Release ID'
description: "Release ID"
upload_url:
description: "URL for uploading assets to the release"
runs:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface Releaser {
draft: boolean | undefined;
prerelease: boolean | undefined;
target_commitish: string | undefined;
discussion_category_name: string | undefined;
}): Promise<{ data: Release }>;

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

allReleases(params: {
Expand Down Expand Up @@ -86,6 +88,7 @@ export class GitHubReleaser implements Releaser {
draft: boolean | undefined;
prerelease: boolean | undefined;
target_commitish: string | undefined;
discussion_category_name: string | undefined;
}): Promise<{ data: Release }> {
return this.github.rest.repos.createRelease(params);
}
Expand All @@ -100,6 +103,7 @@ export class GitHubReleaser implements Releaser {
body: string | undefined;
draft: boolean | undefined;
prerelease: boolean | undefined;
discussion_category_name: string | undefined;
}): Promise<{ data: Release }> {
return this.github.rest.repos.updateRelease(params);
}
Expand Down Expand Up @@ -185,6 +189,8 @@ export const release = async (
(isTag(config.github_ref)
? config.github_ref.replace("refs/tags/", "")
: "");

const discussion_category_name = config.input_discussion_category_name;
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 @@ -246,7 +252,8 @@ export const release = async (
name,
body,
draft,
prerelease
prerelease,
discussion_category_name
});
return release.data;
} catch (error) {
Expand All @@ -273,7 +280,8 @@ export const release = async (
body,
draft,
prerelease,
target_commitish
target_commitish,
discussion_category_name
});
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 @@ -16,6 +16,7 @@ export interface Config {
input_prerelease?: boolean;
input_fail_on_unmatched_files?: boolean;
input_target_commitish?: string;
input_discussion_category_name?: string;
}

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

Expand Down