Skip to content

Commit

Permalink
Allow a prop format to be specified (#61)
Browse files Browse the repository at this point in the history
Co-authored-by: desrosj <desrosj@git.wordpress.org>
Co-authored-by: aaronjorbin <jorbin@git.wordpress.org>
Co-authored-by: noisysocks <noisysocks@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
  • Loading branch information
5 people authored Feb 6, 2024
1 parent d0d6617 commit 64511b5
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 29 deletions.
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
53 changes: 40 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
53 changes: 40 additions & 13 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ 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(',').map(function(value){
return value.trim();
}) || ["git"];

if ( formats.includes('all') ) {
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 +136,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 +159,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

0 comments on commit 64511b5

Please sign in to comment.