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

Allow a prop format to be specified #64

Merged
merged 34 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
131e335
Allow a prop format to be specified.
desrosj Feb 6, 2024
e7a39dc
Correct syntax.
desrosj Feb 6, 2024
fb0788c
Test 'both' value
desrosj Feb 6, 2024
2def9b8
Test svn value.
desrosj Feb 6, 2024
2e24cd6
Switch to expecting an array.
desrosj Feb 6, 2024
002f617
Commit built files.
desrosj Feb 6, 2024
e109b0d
Use `indexOf` instead of `includes`
desrosj Feb 6, 2024
87832d7
Add new option to the example workflow.
desrosj Feb 6, 2024
227d5d0
Simplify logic for detecting formats.
desrosj Feb 6, 2024
29a09eb
Add a debug line that outputs the requested formats.
desrosj Feb 6, 2024
b332783
Return an error if no valid formats are provided.
desrosj Feb 6, 2024
a49f3ac
Fix typo.
desrosj Feb 6, 2024
a08eb2a
Don't compare `includes()` to `0`.
desrosj Feb 6, 2024
f45d0bd
Update some documentation and update test action.
desrosj Feb 6, 2024
0238a17
Expect comma separated values.
desrosj Feb 6, 2024
0126854
Test with a new `format` value.
desrosj Feb 6, 2024
c60a0c1
Test `svn` value.
desrosj Feb 6, 2024
6a820b0
Strip spaces from input and improve docs.
desrosj Feb 6, 2024
0ffcd8e
Rebuild dist folder.
desrosj Feb 6, 2024
85366bd
Coding standards fixes.
desrosj Feb 6, 2024
fc02e9c
Coding standards fixes.
desrosj Feb 6, 2024
488901b
Default value should be an array.
desrosj Feb 6, 2024
c5fdc81
Merge branch 'feature/allow-choice-of-format' of github.com:WordPress…
desrosj Feb 6, 2024
57a3021
Rebuild `dist`.
desrosj Feb 6, 2024
54fd6ce
Setup the new variable with a default
aaronjorbin Feb 6, 2024
4210d2f
Improve how the variables are parsed
aaronjorbin Feb 6, 2024
537f14e
fix yml
aaronjorbin Feb 6, 2024
e7f7b21
Merge branch 'trunk' of github.com:WordPress/props-bot-action into fe…
aaronjorbin Feb 6, 2024
d10995e
add built file
aaronjorbin Feb 6, 2024
dd803e1
Merge branch 'trunk' into feature/allow-choice-of-format
desrosj Feb 8, 2024
bc8e24f
Update action.yml
aaronjorbin Feb 8, 2024
d84ab11
fix newline
aaronjorbin Feb 8, 2024
e58984d
Merge branch 'trunk' into feature/allow-choice-of-format
aaronjorbin Feb 8, 2024
c2428e4
include build
aaronjorbin Feb 8, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/test-action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ jobs:

- name: Run the Action
uses: ./
with:
format: 'all'
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ For a full breakdown of the WordPress project's Props best practices, please con
## Configuration

### Required configurations
| Key | Default | Description |
| --- |-----------------|--------------------------------------------------------------|
| `token` | `$GITHUB_TOKEN` | GitHub token with permission to comment on the pull request. |
| Key | Default | Description |
|----------|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `token` | `$GITHUB_TOKEN` | GitHub token with permission to comment on the pull request. |
| `format` | `git` | The style of contributor lists to include. Accepted values are `svn`, `git`, or `all`, or any combination of those separated by commas. |

## Example Workflow File

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: 'WordPress Props'
description: 'Leaves a list of all contributors associated with a pull request and linked issues in a comment for use within merge commits messages.'
inputs:
format:
description: 'Format of the message. use `git`, `svn`, `all`, or a comma seperate list of those.'
aaronjorbin marked this conversation as resolved.
Show resolved Hide resolved
required: false
default: 'git'
token:
description: 'GitHub secret token.'
required: true
Expand Down
57 changes: 44 additions & 13 deletions dist/index.js

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

6 changes: 6 additions & 0 deletions example-props-bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ jobs:
steps:
- name: Gather a list of contributors
uses: WordPress/props-bot-action@trunk
# Optional arguments.
# with:
# # Allows a custom token to be passed.
# token: ${{ secrets.CUSTOM_PROPS_BOT_TOKEN }}
# # Specify the prop format to display. Default is `git`. Values should be comma separated.
# format: 'all'

- name: Remove the props-bot label
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
Expand Down
57 changes: 44 additions & 13 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ export default class GitHub {
constructor() {
const token = core.getInput("token") || process.env.GITHUB_TOKEN || "";
this.octokit = github.getOctokit(token);

const formats = core.getInput("format").replace(/ /g, '').split(',').filter( value => {
return value.trim();
});


if ( formats.length === 0 ) {
this.format = [ "git" ];
}
else if ( formats.includes('all') ) {
desrosj marked this conversation as resolved.
Show resolved Hide resolved
this.format = ["git", "svn"];
} else if ( formats.includes('svn') || formats.includes('git') ) {
this.format = formats;
} else {
core.error( 'A valid props format was not provided.' );
}
}

/**
Expand Down Expand Up @@ -124,6 +140,9 @@ export default class GitHub {
core.debug( "Contributor list received:" );
core.debug( contributorsList );

core.debug( 'Formats requested:' );
core.debug( this.format );

let prNumber = context.payload?.pull_request?.number;
if ( 'issue_comment' === context.eventName ) {
prNumber = context.payload?.issue?.number;
Expand All @@ -144,22 +163,34 @@ export default class GitHub {
"Contributors, please [read how to link your accounts](https://make.wordpress.org/core/2020/03/19/associating-github-accounts-with-wordpress-org-profiles/) to ensure your work is properly credited in WordPress releases.\n\n";
}

commentMessage += "## Core SVN\n\n" +
"Core Committers: Use this line as a base for the props when committing in SVN:\n" +
"```\n" +
"Props " + contributorsList['svn'].join(', ') + "." +
"\n```\n\n" +
"## GitHub Merge commits\n\n" +
"If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.\n\n" +
"```\n";
if ( this.format.includes('svn') ) {
if ( this.format.includes('git') ) {
commentMessage += "## Core SVN\n\n";
}

if ( contributorsList['unlinked'].length > 0 ) {
commentMessage += "Unlinked contributors: " + contributorsList['unlinked'].join(', ') + ".\n\n";
commentMessage += "Core Committers: Use this line as a base for the props when committing in SVN:\n" +
"```\n" +
"Props " + contributorsList['svn'].join(', ') + "." +
"\n```\n\n";
}

if ( this.format.includes('git') ) {
if ( this.format.includes('svn') ) {
commentMessage += "## GitHub Merge commits\n\n";
}

commentMessage += "If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.\n\n" +
"```\n";

if (contributorsList['unlinked'].length > 0) {
commentMessage += "Unlinked contributors: " + contributorsList['unlinked'].join(', ') + ".\n\n";
}

commentMessage += contributorsList['coAuthored'].join("\n") +
"\n```\n\n";
}

commentMessage += contributorsList['coAuthored'].join("\n") +
"\n```\n\n" +
"**To understand the WordPress project's expectations around crediting contributors, please [review the Contributor Attribution page in the Core Handbook](https://make.wordpress.org/core/handbook/best-practices/contributor-attribution-props/).**\n";
commentMessage += "**To understand the WordPress project's expectations around crediting contributors, please [review the Contributor Attribution page in the Core Handbook](https://make.wordpress.org/core/handbook/best-practices/contributor-attribution-props/).**\n";

const comment = {
...commentInfo,
Expand Down