Skip to content

Commit

Permalink
Allow to mention the contributor in the message.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Feb 11, 2021
1 parent 465c6e4 commit a38583e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Welcome New Contributors
Use this action to welcome the new contributors into your community. This action posts a welcome message whenever a new contributor opens his/her first issue or PR in your repository.
Use this action to welcome new contributors into your community. This action posts a welcome message whenever a new contributor opens his/her first issue or PR in your repository.

Additionally, you can also create your own bot account and use it to post the welcome messages instead of using the default `github-actions` bot.

Expand All @@ -25,7 +25,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Greet the contributor'
uses: garg3133/welcome-new-contributors@v1.1
uses: garg3133/welcome-new-contributors@v1.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-message: 'Hello there, thanks for opening your first issue. We welcome you to the community!'
Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: 'Greet the contributor'
uses: garg3133/welcome-new-contributors@v1.1
uses: garg3133/welcome-new-contributors@v1.2
with:
token: ${{ secrets.BOT_ACCESS_TOKEN }}
is-oauth-token: true
Expand All @@ -64,5 +64,8 @@ jobs:

![Jagrati-Bot](assets/Jagrati-Bot.png)

### Want to tag the contributor in the message?
Use `@contributor_name` anywhere in the message and it will be automatically replaced by the contributor's username.

# License
The scripts and documentation in this project are released under the [MIT License](https://github.com/garg3133/welcome-new-contributors/blob/main/LICENSE)
7 changes: 5 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const run = async () => {
return;
}

// Prepare the final message
const final_message = message.replace(/@contributor_name/g, `@${sender}`);


// To create a comment on a pull request, we hit the issue endpoint only.
// See: https://octokit.github.io/rest.js/v18#pulls-create-review-comment
Expand All @@ -85,15 +88,15 @@ const run = async () => {

const issueType = isIssue ? 'issue' : 'pull request';
// Add a comment to the appropriate place
console.log(`Adding message: ${message} to ${issueType} ${number}`);
console.log(`Adding message: ${final_message} to ${issueType} ${number}`);

// Add comment (greeting) to issue/PR
try {
await client.issues.createComment({
owner,
repo,
issue_number: number,
body: message
body: final_message
});
} catch (error) {
core.setFailed(error.message);
Expand Down
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ const run = async () => {
return;
}

// Prepare the final message
const final_message = message.replace(/@contributor_name/g, `@${sender}`);


// To create a comment on a pull request, we hit the issue endpoint only.
// See: https://octokit.github.io/rest.js/v18#pulls-create-review-comment
Expand All @@ -78,15 +81,15 @@ const run = async () => {

const issueType = isIssue ? 'issue' : 'pull request';
// Add a comment to the appropriate place
console.log(`Adding message: ${message} to ${issueType} ${number}`);
console.log(`Adding message: ${final_message} to ${issueType} ${number}`);

// Add comment (greeting) to issue/PR
try {
await client.issues.createComment({
owner,
repo,
issue_number: number,
body: message
body: final_message
});
} catch (error) {
core.setFailed(error.message);
Expand Down

0 comments on commit a38583e

Please sign in to comment.