diff --git a/.github/workflows/test-action.yml b/.github/workflows/test-action.yml index f987275..d8e3015 100644 --- a/.github/workflows/test-action.yml +++ b/.github/workflows/test-action.yml @@ -26,3 +26,5 @@ jobs: - name: Run the Action uses: ./ + with: + format: 'all' diff --git a/README.md b/README.md index 315955d..e5d64b9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/dist/index.js b/dist/index.js index 82e7221..74850a5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -35289,6 +35289,18 @@ 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.' ); + } } /** @@ -35408,6 +35420,9 @@ 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; @@ -35428,22 +35443,34 @@ 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, diff --git a/example-props-bot.yml b/example-props-bot.yml index 806ca19..d6ebae8 100644 --- a/example-props-bot.yml +++ b/example-props-bot.yml @@ -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 diff --git a/src/github.js b/src/github.js index 2270221..3e033a5 100644 --- a/src/github.js +++ b/src/github.js @@ -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.' ); + } } /** @@ -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; @@ -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,