Skip to content

Commit

Permalink
Updated actions script :brick:
Browse files Browse the repository at this point in the history
  • Loading branch information
ankur12-1610 committed Jan 5, 2022
1 parent af47fd5 commit 991f409
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 232 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pr-activity.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 'Pull Request Action 🚀'

on:
on:
pull_request:
types: [opened]

Expand All @@ -19,9 +19,9 @@ jobs:
with:
GIPHY_TOKEN: ${{ secrets.GIPHY_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_TEXT: 'thanks for submitting a pull request! We will try to review it as soon as we can :)' #enter your custom comment in the content variable
COMMENT_TEXT: 'thanks for submitting a pull request! We will try to review it as soon as we can :)' #enter your custom comment in the content variable
PR_REACTION: 'rocket' #enter your reaction here
GIPHY_TOPIC: 'Thanks a lot' #enter your topic here
TAG_AUTHOR: true #enter true if you want to tag the author of the pull request or enter fase
ASSIGN_TO_AUTHOR: true #enter true if you want to assign the pull request to the author or enter false
FIRST_TIMERS_MESSAGE: ':tada: Thanks for your first contribution in this repo!' #your custom message for the first timers
FIRST_TIMERS_MESSAGE: ':tada: Thanks for your first contribution in this repo!' #your custom message for the first timers
12 changes: 6 additions & 6 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"semi": false,
"singleQuote": true,
"printWidth": 80,
"trailingComma": "all",
"proseWrap": "never",
"overrides": [{ "files": ".prettierrc", "options": { "parser": "json" } }]
"semi": false,
"singleQuote": true,
"printWidth": 80,
"trailingComma": "all",
"proseWrap": "never",
"overrides": [{ "files": ".prettierrc", "options": { "parser": "json" } }]
}
65 changes: 39 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@ This action provides the following functionaliy for the Github Actions users:
---

## 📝 Prerequisites:

You'll need to create a "Repository Secret" of name `GIPHY_TOKEN` and its value should be the API key of [giphy](https://giphy.com/). Here is the [article](https://support.giphy.com/hc/en-us/articles/360020283431-Request-A-GIPHY-API-Key) on how to set up the giphy API KEY.

![giphy-tk](https://user-images.githubusercontent.com/76884959/147668001-4856c7f5-fe79-4ae8-a01d-fb9f1edef88f.png)


## :arrow_up: Usage:

Create a `.github/workflows/pr-activity.yml` file in the repository of your choice, then add following code to it:

```yaml
name: 'Pull Request Action 🚀'

on:
on:
pull_request:
types: [opened]

Expand All @@ -43,53 +45,66 @@ jobs:
with:
GIPHY_TOKEN: ${{ secrets.GIPHY_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_TEXT: 'thanks for submitting a pull request! We will try to review it as soon as we can :)' #enter your custom comment in the content variable
COMMENT_TEXT: 'thanks for submitting a pull request! We will try to review it as soon as we can :)' #enter your custom comment in the content variable
PR_REACTION: 'rocket' #enter your reaction here
GIPHY_TOPIC: 'Thanks a lot' #enter your giphy topic here
TAG_AUTHOR: true #enter true if you want to tag the author of the pull request
ASSIGN_TO_AUTHOR: true #enter true if you want to assign the pull request to the author of the pull request
```

The comment and the reaction to the PR can be customized according to the user.
### 💬 COMMENT_TEXT:

### 💬 COMMENT_TEXT:

The `COMMENT_TEXT` variable can take any string so feel free to enter any comment in this section.

### 🚀 PR_REACTION:

The `PR_REACTION` variable can also be customized. The available reactions are:

| content | emoji |
| ---------- | :-----: |
| `+1` | 👍 |
| `-1` | 👎 |
| `laugh` | 😄 |
| `confused` | 😕 |
| `rocket` | 🚀 |
| `eyes` | 👀 |
| `heart` | ❤️ |
| `hooray` | 🎉 |
| ---------- | :---: |
| `+1` | 👍 |
| `-1` | 👎 |
| `laugh` | 😄 |
| `confused` | 😕 |
| `rocket` | 🚀 |
| `eyes` | 👀 |
| `heart` | ❤️ |
| `hooray` | 🎉 |

### 🏷️ TAG_AUTHOR:

The `TAG_AUTHOR` has either `true` or `false` boolean fields. Assigning `true` will tag the author of the PR in the comment.

### 🏁 ASSIGN_TO_AUTHOR:

The `ASSIGN_TO_AUTHOR` has either `true` or `false` boolean fields. Assigning `true` will assign the PR to the author of the PR.

### If user wants to add GIF to the comment:

### 🪙 GIPHY_TOKEN:

Without `GIPHY_TOKEN` secret, the workflow cannot fetch gifs.

### 📍 GIPHY_TOPIC:

The `GIPHTY_TOPIC` variable can take any input, so whether you want a "thankyou" gif or "welcome" all of them is possible ;) so feel free to exploit it.

---

## Example 🍠:
## Example 🍠:

Take a look at the Demo PRs:

- [Demo PR v1.1](https://github.com/ankur12-1610/pull-request-action/pull/40)
>Code:

> Code:
```yaml
name: 'Pull Request Action 🚀'

on:
on:
pull_request:
types: [opened]

Expand All @@ -102,21 +117,21 @@ Take a look at the Demo PRs:
with:
GIPHY_TOKEN: ${{ secrets.GIPHY_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_TEXT: 'thanks for submitting a pull request! We will try to review it as soon as we can :)' #enter your custom comment in the content variable
COMMENT_TEXT: 'thanks for submitting a pull request! We will try to review it as soon as we can :)' #enter your custom comment in the content variable
PR_REACTION: 'rocket' #enter your reaction here
GIPHY_TOPIC: 'Thanks a lot' #enter your giphy topic here
TAG_AUTHOR: true #enter true if you want to tag the author of the pull request
ASSIGN_TO_AUTHOR: true #enter true if you want to assign the pull request to the author of the pull request


```

- [Demo PR v1.0](https://github.com/ankur12-1610/pull-request-action/pull/10)
>Code:

> Code:
```yaml
name: 'Pull Request Action 🚀'

on:
on:
pull_request:
types: [opened]

Expand All @@ -128,19 +143,17 @@ Take a look at the Demo PRs:
- uses: ankur12-1610/pull-request-action@v1.0
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_TEXT: 'thanks for submitting a pull request! We will try to review it as soon as we can :)' #enter your custom comment in the content variable
COMMENT_TEXT: 'thanks for submitting a pull request! We will try to review it as soon as we can :)' #enter your custom comment in the content variable
PR_REACTION: 'rocket' #enter your reaction here
TAG_AUTHOR: true #enter true if you want to tag the author of the pull request
ASSIGN_TO_AUTHOR: true #enter true if you want to assign the pull request to the author of the pull request

```

# Inspired From

> [:speech_balloon: Auto Comment](https://github.com/wow-actions/auto-comment)

## License 🔖:
## License 🔖:

The scripts and documentation in this project are released under the [MIT License](LICENSE)

Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inputs:
COMMENT_TEXT:
description: Body of the comment
required: true
PR_REACTION:
PR_REACTION:
description: Reaction to the comment
required: false
TAG_AUTHOR:
Expand All @@ -33,5 +33,5 @@ branding:
icon: tag

runs:
using: 'docker'
image: 'Dockerfile'
using: 'docker'
image: 'Dockerfile'
34 changes: 15 additions & 19 deletions bin/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const { context } = require('@actions/github');
//taking input from the core
const GIPHY_TOKEN = core.getInput('GIPHY_TOKEN');
const GITHUB_TOKEN = core.getInput('GITHUB_TOKEN');
const COMMENT_TEXT = core.getInput('COMMENT_TEXT');
Expand All @@ -40,30 +41,25 @@ function run() {
const { pull_request } = context.payload;
const payload = context.payload.pull_request;
const author = payload.user.login;
const tag_text = (TAG_AUTHOR ? `@` + author + ` ` : null);
const assignee = (ASSIGN_TO_AUTHOR ? author : null);
const client = new github.getOctokit(GITHUB_TOKEN);
//get no of prs created by author
const prs_by_author = yield octokit.rest.pulls.list({
owner: author,
repo: context.repo.repo,
client: client,
sender: author,
state: 'all'
});
const prs_by_author_count = prs_by_author.data.length;
console.log(`${prs_by_author_count} PRs created by ${author}`);
//comment to first timers
let first_timers_comment = '';
if (prs_by_author_count > 1) {
first_timers_comment = FIRST_TIMERS_MESSAGE ? FIRST_TIMERS_MESSAGE : `Thanks for the PR!`;
}
const creator = context.payload.sender.login;
const tag_text = TAG_AUTHOR ? `@` + author + ` ` : null;
const assignee = ASSIGN_TO_AUTHOR ? author : null;
//comment on PR
yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, context.repo), { issue_number: pull_request.number, body: tag_text + COMMENT_TEXT + gif + first_timers_comment, id: payload.number.toString() }));
yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, context.repo), { issue_number: pull_request.number, body: tag_text + COMMENT_TEXT + gif, id: payload.number.toString() }));
//assign PR to its author
yield octokit.rest.issues.addAssignees(Object.assign(Object.assign({}, context.repo), { issue_number: pull_request.number, assignees: assignee }));
//add reaction to PR
yield octokit.rest.reactions.createForIssue(Object.assign(Object.assign({}, context.repo), { repo: context.repo.repo, issue_number: pull_request.number, content: PR_REACTION, owner: context.repo.owner }));
//for first timers
const pulls = yield octokit.rest.pulls.list(Object.assign(Object.assign({}, context.repo), { state: 'all', sort: 'created', direction: 'desc' }));
console.log('Checking...');
if (pulls.data.length === 1) {
console.log('First pull request!');
yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, context.repo), { issue_number: pull_request.number, body: FIRST_TIMERS_MESSAGE, id: payload.number.toString() }));
}
else {
console.log('Not first pull request');
}
}
catch (e) {
core.error(e);
Expand Down
122 changes: 0 additions & 122 deletions bin/ftimers.js

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
"bin"
],
"scripts": {
"lint": "eslint 'src/**.js' --fix",
"test": "eslint 'src/**.js'",
"build": "tsc",
"prepare": "is-ci || husky install .husky"
},
Expand Down Expand Up @@ -48,6 +46,7 @@
"@actions/github": "^5.0.0",
"@actions/io": "^1.0.0",
"@actions/tool-cache": "^1.7.1",
"@octokit/endpoint": "^6.0.12",
"@types/axios": "^0.14.0",
"@types/node": "^17.0.5",
"@vercel/ncc": "^0.33.1",
Expand Down

0 comments on commit 991f409

Please sign in to comment.