Skip to content

Commit

Permalink
feat: check non-stargazer and give a tip message
Browse files Browse the repository at this point in the history
  • Loading branch information
bubkoo committed Feb 2, 2023
1 parent 72c6058 commit 97dbbac
Show file tree
Hide file tree
Showing 8 changed files with 1,759 additions and 1,618 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<h1 align="center">Welcome</h1>


<p align="center">
<a href="https://github.com/wow-actions/welcome/actions/workflows/release.yml"><img alt="build" src="https://img.shields.io/github/actions/workflow/status/wow-actions/welcome/release.yml?branch=master&logo=github&style=flat-square" ></a>
<a href="/wow-actions/welcome/blob/master/LICENSE"><img alt="MIT License" src="https://img.shields.io/github/license/wow-actions/welcome?style=flat-square"></a>
Expand All @@ -10,7 +9,6 @@
<a href="https://lgtm.com/projects/g/wow-actions/welcome/context:javascript" rel="nofollow"><img alt="Language grade: JavaScript" src="https://img.shields.io/lgtm/grade/javascript/g/wow-actions/welcome.svg?logo=lgtm&style=flat-square" ></a>
</p>


<p align="center"><strong>Welcome new users by creating a comment in the first time issue/PR</strong></p>

![first-issue](https://github.com/wow-actions/welcome/blob/master/screenshots/first-issue.jpg?raw=true)
Expand Down Expand Up @@ -44,6 +42,8 @@ jobs:
FIRST_PR_MERGED: |
🎉 @{{ author }}
Congrats on merging your first pull request! We here at behaviorbot are proud of you!
STAR_MESSAGE: If you like this project, please ⭐star⭐ our repo.
```
### Inputs
Expand All @@ -54,13 +54,14 @@ Various inputs are defined to let you configure the action:
| Name | Description | Default |
| --- | --- | --- |
| `GITHUB_TOKEN` | The GitHub token for authentication | N/A |
| `FIRST_ISSUE` <br> or <br> `FIRST_ISSUE_COMMENT` | Comment to be posted to on first time issues | |
| `FIRST_ISSUE_REACTIONS` | Reactions to be add to comment on first time issues | |
| `FIRST_PR` <br> or <br> `FIRST_PR_COMMENT` | Comment to be posted to on PRs from first time contributors in your repository | |
| `FIRST_PR_REACTIONS` | Reactions to be add to comment on PRs from first time contributors in your repository | |
| `FIRST_PR_MERGED` <br> or <br> `FIRST_PR_MERGED_COMMENT` | Comment to be posted to on pull requests merged by a first time user | |
| `FIRST_PR_MERGED_REACTIONS` | Reactions to be add to comment on pull requests merged by a first time user | |
| `GITHUB_TOKEN` | The GitHub token for authentication. | N/A |
| `FIRST_ISSUE` <br> or <br> `FIRST_ISSUE_COMMENT` | Comment to be posted to on first time issues. | |
| `FIRST_ISSUE_REACTIONS` | Reactions to be add to comment on first time issues. | |
| `FIRST_PR` <br> or <br> `FIRST_PR_COMMENT` | Comment to be posted to on PRs from first time contributors in your repository. | |
| `FIRST_PR_REACTIONS` | Reactions to be add to comment on PRs from first time contributors in your repository. | |
| `FIRST_PR_MERGED` <br> or <br> `FIRST_PR_MERGED_COMMENT` | Comment to be posted to on pull requests merged by a first time user. | |
| `FIRST_PR_MERGED_REACTIONS` | Reactions to be add to comment on pull requests merged by a first time user. | |
| `STAR_MESSAGE` | Message in the comment to tip non-stargazers to star our repo. | |

Available reactions:

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ inputs:
description: Reactions to be add to comment on pull requests merged by a first time user.
required: false

STAR_MESSAGE:
description: Message in the comment to tip non-stargazers to star our repo.
required: false

runs:
using: node16
main: dist/index.js
Expand Down
49 changes: 16 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,31 @@
"eslint --fix"
]
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"repository": "https://github.com/wow-actions/welcome-action",
"license": "MIT",
"author": {
"name": "bubkoo",
"email": "[email protected]"
},
"contributors": [],
"repository": "https://github.com/wow-actions/welcome-action",
"dependencies": {
"@actions/core": "^1.5.0",
"@actions/github": "^5.0.0",
"lodash.random": "^3.2.0",
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"mustache": "^4.2.0"
},
"devDependencies": {
"@commitlint/cli": "^13.1.0",
"@commitlint/config-conventional": "^13.1.0",
"@types/lodash.random": "^3.2.6",
"@types/mustache": "^4.1.2",
"@types/node": "^16.9.1",
"@typescript-eslint/eslint-plugin": "^4.18.0",
"@typescript-eslint/parser": "^4.18.0",
"@vercel/ncc": "^0.31.1",
"devmoji": "^2.3.0",
"eslint": "^7.22.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-promise": "^5.1.0",
"husky": "^7.0.2",
"is-ci": "^3.0.0",
"lint-staged": "^11.1.2",
"@bubkoo/commitlint-config": "^1.0.1",
"@bubkoo/eslint-config": "^1.3.0",
"@bubkoo/tsconfig": "^1.1.0",
"@types/mustache": "^4.2.2",
"@types/node": "^18.11.18",
"@vercel/ncc": "^0.36.1",
"eslint": "^8.33.0",
"husky": "^8.0.3",
"is-ci": "^3.0.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.4.1",
"pretty-quick": "^3.1.1",
"rimraf": "^3.0.2",
"typescript": "^4.4.3"
"prettier": "^2.8.3",
"pretty-quick": "^3.1.3",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
}
}
94 changes: 0 additions & 94 deletions src/action.ts

This file was deleted.

94 changes: 92 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,93 @@
import { Action } from './action'
import * as core from '@actions/core'
import * as github from '@actions/github'
import { addReactions } from './reaction'
import { getOctokit, getComment } from './util'

Action.run()
async function run(context = github.context) {
core.debug(`event: ${context.eventName}`)
core.debug(`action: ${context.payload.action}`)

try {
const event = context.eventName
const { action } = context.payload
const { issue } = context.payload
const pr = context.payload.pull_request
const isIssue = event === 'issues' && issue != null
const isPR =
(event === 'pull_request' || event === 'pull_request_target') &&
pr != null

if ((isIssue || isPR) && action === 'opened') {
const comment =
issue != null
? core.getInput('FIRST_ISSUE') || core.getInput('FIRST_ISSUE_COMMENT')
: core.getInput('FIRST_PR') || core.getInput('FIRST_PR_COMMENT')
const reactions =
issue != null
? core.getInput('FIRST_ISSUE_REACTIONS')
: core.getInput('FIRST_PR_REACTIONS')

if (comment) {
const entity = (issue || pr)!
const author = entity.user.login
const octokit = getOctokit()
const response = await octokit.rest.issues.listForRepo({
...context.repo,
state: 'all',
creator: author,
})

const list = response.data.filter((data) =>
issue != null ? !data.pull_request : data.pull_request,
)

if (list.length === 1) {
const { data } = await octokit.rest.issues.createComment({
...context.repo,
issue_number: entity.number,
body: await getComment(octokit, comment, { author }),
})

if (reactions) {
await addReactions(octokit, data.id, reactions)
}
}
}
} else if (isPR && action === 'closed' && pr != null) {
const comment =
core.getInput('FIRST_PR_MERGED') ||
core.getInput('FIRST_PR_MERGED_COMMENT')
const reactions = core.getInput('FIRST_PR_MERGED_REACTIONS')

if (pr.merged && comment) {
const author = pr.user.login
const { owner, repo } = context.repo
const octokit = getOctokit()
const res = await octokit.rest.search.issuesAndPullRequests({
q: `is:pr is:merged author:${author} repo:${owner}/${repo}`,
})

const merged = res.data.items.filter(
(item) => item.number !== pr.number,
)

if (merged.length === 0) {
const { data } = await octokit.rest.issues.createComment({
...context.repo,
issue_number: pr.number,
body: await getComment(octokit, comment, { author }),
})

if (reactions) {
await addReactions(octokit, data.id, reactions)
}
}
}
}
} catch (e) {
core.error(e)
core.setFailed(e.message)
}
}

run()
Loading

0 comments on commit 97dbbac

Please sign in to comment.