-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for configuring the pull request created by the action. Closes #57
- Loading branch information
1 parent
417b74b
commit 2138a68
Showing
10 changed files
with
668 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"printWidth": 140, | ||
"printWidth": 120, | ||
"singleQuote": true, | ||
"tabWidth": 4, | ||
"overrides": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Update license copyright year(s) | ||
description: Updates the copyright year(s) in your license file and creates a pull request. | ||
author: Mattias Kindborg <mattias.kindborg@gmail.com> (https://twitter.com/FantasticFiasco) | ||
inputs: | ||
token: | ||
description: > | ||
Personal access token (PAT) used to fetch the repository. The PAT is configured | ||
with the local git config, which enables your scripts to run authenticated git | ||
commands. The post-job step removes the PAT. | ||
We recommend using a service account with the least permissions necessary. | ||
Also when generating a new PAT, select the least scopes necessary. | ||
[Learn more about creating and using encrypted secrets](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) | ||
default: ${{ github.token }} | ||
required: false | ||
branchName: | ||
description: The branch name template with support for substituting variable {{ currentYear }}. | ||
default: license/copyright-to-{{ currentYear }} | ||
required: false | ||
commitMessage: | ||
description: The git commit message | ||
default: "docs(license): update copyright year(s)" | ||
required: false | ||
commitBody: | ||
description: > | ||
The git commit body that will be appended to commit message, separated by two line returns | ||
default: "" | ||
required: false | ||
prTitle: | ||
description: The title of the new pull request | ||
default: Update license copyright year(s) | ||
required: false | ||
prBody: | ||
description: The contents of the pull request | ||
default: "" | ||
required: false | ||
assignees: | ||
description: > | ||
Comma-separated list with usernames of people to assign when pull request is created | ||
default: "" | ||
required: false | ||
labels: | ||
description: Comma-separated list of labels to add when pull request is created | ||
default: "" | ||
required: false | ||
runs: | ||
using: node12 | ||
main: ./dist/index.js | ||
branding: | ||
icon: sunrise | ||
color: orange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
const { getInput } = require('@actions/core'); | ||
|
||
const CURRENT_YEAR = new Date().getFullYear(); | ||
|
||
const DEFAULT_BRANCH_NAME = 'license/copyright-to-{ currentYear }'; | ||
const DEFAULT_COMMIT_MESSAGE = 'docs(license): update copyright year(s)'; | ||
const DEFAULT_COMMIT_BODY = ''; | ||
const DEFAULT_PR_TITLE = 'Update license copyright year(s)'; | ||
const DEFAULT_PR_BODY = ''; | ||
const DEFAULT_ASSIGNEES = ''; | ||
const DEFAULT_LABELS = ''; | ||
|
||
function parseConfig() { | ||
const token = getInput('token', { required: true }); | ||
const branchName = substituteVariable( | ||
getInput('branchName') || DEFAULT_BRANCH_NAME, | ||
'currentYear', | ||
CURRENT_YEAR.toString() | ||
); | ||
const commitMessage = getInput('commitMessage') || DEFAULT_COMMIT_MESSAGE; | ||
const commitBody = getInput('commitBody') || DEFAULT_COMMIT_BODY; | ||
const pullRequestTitle = getInput('prTitle') || DEFAULT_PR_TITLE; | ||
const pullRequestBody = getInput('prBody') || DEFAULT_PR_BODY; | ||
const assignees = splitCsv(getInput('assignees') || DEFAULT_ASSIGNEES); | ||
const labels = splitCsv(getInput('labels') || DEFAULT_LABELS); | ||
|
||
return { | ||
token, | ||
branchName, | ||
commitMessage, | ||
commitBody, | ||
pullRequestTitle, | ||
pullRequestBody, | ||
assignees, | ||
labels, | ||
}; | ||
} | ||
|
||
/** | ||
* @param {string} text | ||
* @param {string} variableName | ||
* @param {string} variableValue | ||
*/ | ||
function substituteVariable(text, variableName, variableValue) { | ||
const variableRegExp = /{\s*(\w+)\s*}/; | ||
const match = text.match(variableRegExp); | ||
if (!match) { | ||
return text; | ||
} | ||
if (match[1] !== variableName) { | ||
throw new Error(`Configuration "${text}" contains unknown variable "${match[1]}"`); | ||
} | ||
return text.replace(variableRegExp, variableValue); | ||
} | ||
|
||
/** | ||
* @param {string} values A comma-separated list of values | ||
*/ | ||
function splitCsv(values) { | ||
return values | ||
.split(',') | ||
.map((value) => value.trim()) // Allow whitespaces in comma-separated list of values | ||
.filter((value) => value !== ''); // Remove empty entries | ||
} | ||
|
||
module.exports = { | ||
parseConfig, | ||
CURRENT_YEAR, | ||
DEFAULT_BRANCH_NAME, | ||
DEFAULT_COMMIT_MESSAGE, | ||
DEFAULT_COMMIT_BODY, | ||
DEFAULT_PR_TITLE, | ||
DEFAULT_PR_BODY, | ||
DEFAULT_ASSIGNEES, | ||
DEFAULT_LABELS, | ||
}; |
Oops, something went wrong.