Skip to content

Commit

Permalink
Release v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lekterable committed Nov 8, 2019
1 parent 0bb1173 commit 0587287
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 24 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Invite contributor to the organization
uses: lekterable/inclusive-organization-action@v1.0.0
uses: lekterable/inclusive-organization-action@v1.1.0
with:
organization: your-organization-name
team: your-team-name
comment: Single or multiline comment
env:
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
```
**NOTE:** replace *`your-organization-name`* with the name of the organization you want to invite contributors to and create a [repository secret](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) called *`ACCESS_TOKEN`* and as a value provide a GitHub [personal access token](https://github.com/settings/tokens) with the scope of *`admin:org`*.
***organization*** - *(required)* name of the organization to which you would like to invite your contributors
***team*** - *(optional)* name of the team within your organization to which you would like to add your contributors
***comment*** - *(optional)* single or multiline *(use yaml syntax)* comment which will be added, when contributor's first PR gets merged
**NOTE:** create a [repository secret](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) called *`ACCESS_TOKEN`* *(or give it another name, but don't forget to change it in the workflow)* and as a value provide a GitHub [personal access token](https://github.com/settings/tokens) with the scope of *`admin:org`*, if you want to be able to add comments you will also need *`public_repo`* .

## License

Expand Down
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ inputs:
organization:
description: Name of the organization to which you would like to invite contributors.
required: true
team:
description: Name of the team within organization to which you would like to add contributors.
required: false
comment:
description: A comment which will be posted on the contributors PR.
required: false
runs:
using: node12
main: dist/index.js
65 changes: 55 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,9 +524,13 @@ module.exports = require("os");
const core = __webpack_require__(470)
const github = __webpack_require__(469)

const transformTeamName = teamName => teamName.toLowerCase().replace(' ', '-')

const run = async () => {
try {
const organization = core.getInput('organization', { required: true })
const teamName = core.getInput('team')
const comment = core.getInput('comment')
const { ACCESS_TOKEN } = process.env

if (!ACCESS_TOKEN)
Expand All @@ -545,27 +549,68 @@ const run = async () => {
const isMergeCommit = commit.data.parents.length > 1
if (!isMergeCommit) return

const { data } = await octokit.repos.listPullRequestsAssociatedWithCommit({
const {
data: [pullRequest],
} = await octokit.repos.listPullRequestsAssociatedWithCommit({
owner: repository.owner.login,
repo: repository.name,
commit_sha: sha,
})

const contributor = data[0].user
const contributor = pullRequest.user

try {
await octokit.orgs.checkMembership({
if (teamName) {
const team = await octokit.teams.getByName({
org: organization,
username: contributor.login,
team_slug: transformTeamName(teamName),
})
} catch (_) {

try {
await octokit.orgs.createInvitation({
await octokit.teams.getMembership({
team_id: team.data.id,
username: contributor.login,
})
} catch (_) {
try {
await octokit.teams.addOrUpdateMembership({
team_id: team.data.id,
username: contributor.login,
})

if (comment)
await octokit.issues.createComment({
owner: repository.owner.login,
repo: repository.name,
issue_number: pullRequest.number,
body: comment,
})
} catch (error) {
core.setFailed(error.message)
}
}
} else {
try {
await octokit.orgs.checkMembership({
org: organization,
invitee_id: contributor.id,
username: contributor.login,
})
} catch (error) {
core.setFailed(error.message)
} catch (_) {
try {
await octokit.orgs.createInvitation({
org: organization,
invitee_id: contributor.id,
})

if (comment)
await octokit.issues.createComment({
owner: repository.owner.login,
repo: repository.name,
issue_number: pullRequest.number,
body: comment,
})
} catch (error) {
core.setFailed(error.message)
}
}
}
} catch (error) {
Expand Down
65 changes: 55 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
const core = require('@actions/core')
const github = require('@actions/github')

const transformTeamName = teamName => teamName.toLowerCase().replace(' ', '-')

const run = async () => {
try {
const organization = core.getInput('organization', { required: true })
const teamName = core.getInput('team')
const comment = core.getInput('comment')
const { ACCESS_TOKEN } = process.env

if (!ACCESS_TOKEN)
Expand All @@ -22,27 +26,68 @@ const run = async () => {
const isMergeCommit = commit.data.parents.length > 1
if (!isMergeCommit) return

const { data } = await octokit.repos.listPullRequestsAssociatedWithCommit({
const {
data: [pullRequest],
} = await octokit.repos.listPullRequestsAssociatedWithCommit({
owner: repository.owner.login,
repo: repository.name,
commit_sha: sha,
})

const contributor = data[0].user
const contributor = pullRequest.user

try {
await octokit.orgs.checkMembership({
if (teamName) {
const team = await octokit.teams.getByName({
org: organization,
username: contributor.login,
team_slug: transformTeamName(teamName),
})
} catch (_) {

try {
await octokit.orgs.createInvitation({
await octokit.teams.getMembership({
team_id: team.data.id,
username: contributor.login,
})
} catch (_) {
try {
await octokit.teams.addOrUpdateMembership({
team_id: team.data.id,
username: contributor.login,
})

if (comment)
await octokit.issues.createComment({
owner: repository.owner.login,
repo: repository.name,
issue_number: pullRequest.number,
body: comment,
})
} catch (error) {
core.setFailed(error.message)
}
}
} else {
try {
await octokit.orgs.checkMembership({
org: organization,
invitee_id: contributor.id,
username: contributor.login,
})
} catch (error) {
core.setFailed(error.message)
} catch (_) {
try {
await octokit.orgs.createInvitation({
org: organization,
invitee_id: contributor.id,
})

if (comment)
await octokit.issues.createComment({
owner: repository.owner.login,
repo: repository.name,
issue_number: pullRequest.number,
body: comment,
})
} catch (error) {
core.setFailed(error.message)
}
}
}
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "inclusive-organization-action",
"version": "1.0.0",
"version": "1.1.0",
"description": "Invite contributors to your GitHub organization when their first PR gets merged, to make them feel welcome and included.",
"scripts": {
"build": "ncc build index.js"
Expand Down

0 comments on commit 0587287

Please sign in to comment.