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

feat: Allow for passing custom merge target #838

Merged
merged 1 commit into from
Feb 25, 2022
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 .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
exec craft publish ${{ fromJSON(steps.inputs.outputs.result).version }};
"
env:
CRAFT_MERGE_TARGET: ${{ fromJSON(steps.inputs.outputs.result).merge_target }}
CRAFT_LOG_LEVEL: ${{ secrets.CRAFT_LOG_LEVEL }}
CRAFT_DRY_RUN: ${{ fromJSON(steps.inputs.outputs.result).dry_run }}
GIT_COMMITTER_NAME: getsentry-bot
Expand Down
4 changes: 4 additions & 0 deletions src/publish/__tests__/fail.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ beforeAll(() => {
body: `
Requested by: @BYK

Merge target: (default)

Quick links:
- [View changes](https://github.com/getsentry/sentry/compare/21.3.0...refs/heads/releases/21.3.1)
- [View check runs](https://github.com/getsentry/sentry/commit/7e5ca7ed5581552de066e2a8bc295b8306be38ac/checks/)
Expand Down Expand Up @@ -141,6 +143,8 @@ describe.each([false, true])("state file exists: %s", (stateFileExists) => {
Object {
"body": "
Requested by: @BYK

Merge target: (default)

Quick links:
- [View changes](https://github.com/getsentry/sentry/compare/21.3.0...refs/heads/releases/21.3.1)
Expand Down
47 changes: 47 additions & 0 deletions src/publish/__tests__/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const inputsArgs = deepFreeze({
body: `
Requested by: @BYK

Merge target: custom-branch

Quick links:
- [View changes](https://github.com/getsentry/sentry/compare/21.3.0...refs/heads/releases/21.3.1)
- [View check runs](https://github.com/getsentry/sentry/commit/7e5ca7ed5581552de066e2a8bc295b8306be38ac/checks/)
Expand All @@ -52,6 +54,51 @@ test("parse inputs", async () => {
expect(result).toMatchInlineSnapshot(`
Object {
"dry_run": "",
"merge_target": "custom-branch",
"path": ".",
"repo": "sentry",
"targets": Array [
"github",
"docker[latest]",
],
"version": "21.3.1",
}
`);
});


const defaultTargetInputsArgs = deepFreeze({
context: {
repo: { owner: "getsentry", repo: "publish" },
payload: {
issue: {
number: "223",
title: "publish: getsentry/[email protected]",
body: `
Requested by: @BYK
Merge target: (default)
Quick links:
- [View changes](https://github.com/getsentry/sentry/compare/21.3.0...refs/heads/releases/21.3.1)
- [View check runs](https://github.com/getsentry/sentry/commit/7e5ca7ed5581552de066e2a8bc295b8306be38ac/checks/)
Assign the **accepted** label to this issue to approve the release.
### Targets\r
- [x] github\r
- [ ] pypi\r
- [ ] docker[release]
- [x] docker[latest]\r
`,
labels: ["accepted"],
},
},
},
});

test("Do not extract merge_target value if its a default value", async () => {
const result = await inputs(defaultTargetInputsArgs);
expect(result).toMatchInlineSnapshot(`
Object {
"dry_run": "",
"merge_target": "",
"path": ".",
"repo": "sentry",
"targets": Array [
Expand Down
12 changes: 11 additions & 1 deletion src/publish/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ exports.default = async function inputs({ context }) {
: "";
const path = "." + (titleMatch.path || "");

// https://docs.github.com/en/get-started/using-git/dealing-with-special-characters-in-branch-and-tag-names#naming-branches-and-tags
const mergeTargetParser = /^Merge target: (?<merge_target>[\w.\-/]+)$/m;
const mergeTargetMatch = context.payload.issue.body.match(
mergeTargetParser
)
let merge_target = '';
if (mergeTargetMatch && mergeTargetMatch.groups) {
merge_target = mergeTargetMatch.groups.merge_target || ''
}

const targetsParser = /^(?!### Targets$\s)(?: *- \[[ x]\] [\w.[\]-]+$(?:\r?\n)?)+/m;
const targetsMatch = context.payload.issue.body.match(targetsParser);
let targets;
Expand All @@ -16,5 +26,5 @@ exports.default = async function inputs({ context }) {
);
}

return { ...titleMatch, path, dry_run, targets };
return { ...titleMatch, merge_target, path, dry_run, targets };
};