Skip to content

Commit

Permalink
refactor: default value (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
bicstone authored Dec 29, 2023
1 parent 4d11ab7 commit 519a49c
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 174 deletions.
48 changes: 0 additions & 48 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,84 +20,36 @@ inputs:
fix_keywords:
description: Keywords to change the status of the issue to fixed
required: false
default: |-
#fix
#fixes
#fixed
close_keywords:
description: Keywords to change the status of the issue to closed
required: false
default: |-
#close
#closes
#closed
push_comment_template:
description: The template for backlog issue comment on push events
required: false
default: |-
<%= commits[0].author.name %>さんが[<%= ref.name %>](<%= ref.url %>)にプッシュしました
<% commits.forEach(commit=>{ %>
+ [<%= commit.comment %>](<%= commit.url %>) (<% print(commit.id.slice(0, 7)) %>)<% }); %>
pr_opened_comment_template:
description: The template for backlog issue comment on opened a pull request
required: false
default: |-
<%= sender.login %>さんがプルリクエストを作成しました
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
pr_reopened_comment_template:
description: The template for backlog issue comment on reopened a pull request
required: false
default: |-
<%= sender.login %>さんがプルリクエストを作成しました
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
pr_ready_for_review_comment_template:
description: The template for backlog issue comment on ready to review a pull request
required: false
default: |-
<%= sender.login %>さんがプルリクエストを作成しました
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
pr_closed_comment_template:
description: The template for backlog issue comment on closed a pull request
required: false
default: |-
<%= sender.login %>さんがプルリクエストをクローズしました
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
pr_merged_comment_template:
description: The template for backlog issue comment on merged a pull request
required: false
default: |-
<%= sender.login %>さんがプルリクエストをマージしました
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
commit_message_reg_template:
description: The template for regular expressions to parse commit messages
required: false
default: "\
^\
(<%= projectKey %>\\-\\d+)\\s?\
(.*?)?\\s?\
(<% print(fixKeywords.join('|')) %>|<% print(closeKeywords.join('|')) %>)?\
$\
"
pr_title_reg_template:
description: The template for regular expressions to parse pull request title
required: false
default: "\
^\
(<%= projectKey %>\\-\\d+)\\s?\
(.*?)?\\s?\
(<% print(fixKeywords.join('|')) %>|<% print(closeKeywords.join('|')) %>)?\
$\
"
fix_status_id:
description: Status ID to mark as fixed
required: false
default: 3
close_status_id:
description: Status ID to mark as closed
required: false
default: 4
88 changes: 50 additions & 38 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 21 additions & 51 deletions src/main/getConfigs.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
/* eslint-disable @typescript-eslint/naming-convention */

import { getConfigs, Configs } from "./getConfigs"
import {
getConfigs,
Configs,
defaultConfigs,
RequiredConfigKeys,
} from "./getConfigs"

const requiredEnv = {
// whitespace added before and after the value
Expand All @@ -27,11 +32,14 @@ const optionalEnv = {
PR_TITLE_REG_TEMPLATE: "prTitleRegTemplate",
}

const configs: Configs = {
const requiredConfigs: Pick<Configs, RequiredConfigKeys> = {
projectKey: "projectKey",
apiHost: "apiHost",
apiKey: "apiKey",
githubEventPath: "githubEventPath",
}

const optionalConfigs: Omit<Configs, RequiredConfigKeys> = {
fixKeywords: ["fixKeyword1", "fixKeyword2"],
closeKeywords: ["closeKeyword1", "closeKeyword2"],
pushCommentTemplate: "pushCommentTemplate",
Expand All @@ -58,14 +66,20 @@ describe("getConfigs", () => {
})

test("getConfigs return trimmed configs", () => {
expect(getConfigs()).toStrictEqual(configs)
expect(getConfigs()).toStrictEqual({
...requiredConfigs,
...optionalConfigs,
})
})

test.each(Object.keys(requiredEnv))(
"getConfigs does not throw when %s is defined only by env",
(key) => {
process.env[`INPUT_${key}`] = ""
expect(getConfigs()).toStrictEqual(configs)
expect(getConfigs()).toStrictEqual({
...requiredConfigs,
...optionalConfigs,
})
},
)

Expand All @@ -83,7 +97,7 @@ describe("getConfigs", () => {
(key) => {
process.env[key] = ""
process.env[`INPUT_${key}`] = ""
expect(() => getConfigs()).not.toThrowError()
expect(() => getConfigs()).not.toThrow()
},
)

Expand All @@ -95,52 +109,8 @@ describe("getConfigs", () => {
process.env[`INPUT_${key}`] = ``
})
expect(getConfigs()).toStrictEqual({
...configs,
// parseCommits.ts of version 2.x.x
fixKeywords: ["#fix", "#fixes", "#fixed"],
closeKeywords: ["#close", "#closes", "#closed"],
// postComments.ts of version 2.x.x
pushCommentTemplate:
"<%= commits[0].author.name %>さんが[<%= ref.name %>](<%= ref.url %>)にプッシュしました" +
"\n" +
"<% commits.forEach(commit=>{ %>" +
"\n" +
"+ [<%= commit.comment %>](<%= commit.url %>) (<% print(commit.id.slice(0, 7)) %>)" +
"<% }); %>",
prOpenedCommentTemplate:
"<%= sender.login %>さんがプルリクエストを作成しました" +
"\n\n" +
"+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)",
prReopenedCommentTemplate:
"<%= sender.login %>さんがプルリクエストを作成しました" +
"\n\n" +
"+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)",
prReadyForReviewCommentTemplate:
"<%= sender.login %>さんがプルリクエストを作成しました" +
"\n\n" +
"+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)",
prClosedCommentTemplate:
"<%= sender.login %>さんがプルリクエストをクローズしました" +
"\n\n" +
"+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)",
prMergedCommentTemplate:
"<%= sender.login %>さんがプルリクエストをマージしました" +
"\n\n" +
"+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)",
commitMessageRegTemplate:
"^" +
"(<%= projectKey %>\\-\\d+)\\s?" +
"(.*?)?\\s?" +
"(<% print(fixKeywords.join('|')) %>|<% print(closeKeywords.join('|')) %>)?" +
"$",
prTitleRegTemplate:
"^" +
"(<%= projectKey %>\\-\\d+)\\s?" +
"(.*?)?\\s?" +
"(<% print(fixKeywords.join('|')) %>|<% print(closeKeywords.join('|')) %>)?" +
"$",
fixStatusId: "3",
closeStatusId: "4",
...defaultConfigs,
...requiredConfigs,
})
})
})
Loading

0 comments on commit 519a49c

Please sign in to comment.