├── .gitignore ├── .prettierrc ├── .huskyrc ├── .editorconfig ├── action.yml ├── package.json ├── LICENSE ├── README.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true 4 | } 5 | -------------------------------------------------------------------------------- /.huskyrc: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "pre-commit": "pretty-quick --staged && npm run build && git add dist" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | end_of_line = lf 10 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: Inclusive Organization 2 | description: Invite contributors to your GitHub organization when their first PR gets merged, to make them feel welcome and included. 3 | author: Kornel Dubieniecki 4 | branding: 5 | icon: award 6 | color: green 7 | inputs: 8 | organization: 9 | description: Name of the organization to which you would like to invite contributors. 10 | required: true 11 | team: 12 | description: Name of the team within organization to which you would like to add contributors. 13 | required: false 14 | comment: 15 | description: A comment which will be posted on the contributors PR. 16 | required: false 17 | runs: 18 | using: node12 19 | main: dist/index.js 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "inclusive-organization-action", 3 | "version": "1.1.0", 4 | "description": "Invite contributors to your GitHub organization when their first PR gets merged, to make them feel welcome and included.", 5 | "scripts": { 6 | "build": "ncc build index.js" 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git+https://github.com/lekterable/inclusive-organization-action.git" 11 | }, 12 | "keywords": [ 13 | "github", 14 | "action", 15 | "actions", 16 | "invite", 17 | "organization", 18 | "workflow" 19 | ], 20 | "author": "Kornel Dubieniecki", 21 | "license": "MIT", 22 | "bugs": { 23 | "url": "https://github.com/lekterable/inclusive-organization-action/issues" 24 | }, 25 | "homepage": "https://github.com/lekterable/inclusive-organization-action#readme", 26 | "dependencies": { 27 | "@actions/core": "^1.2.4", 28 | "@actions/github": "^3.0.0" 29 | }, 30 | "devDependencies": { 31 | "@zeit/ncc": "^0.22.3", 32 | "husky": "^4.2.5", 33 | "prettier": "^2.0.5", 34 | "pretty-quick": "^2.0.1" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Kornel Dubieniecki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 💌 Inclusive Organization 2 | 3 | Invite contributors to your GitHub organization when their first PR gets merged, to make them feel welcome and included. 4 | 5 | ## Usage 6 | 7 | ```yaml 8 | name: Inclusive Organization 9 | on: 10 | push: 11 | branches: master 12 | jobs: 13 | invite: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Invite contributor to the organization 17 | uses: lekterable/inclusive-organization-action@v1.1.0 18 | with: 19 | organization: your-organization-name 20 | team: your-team-name 21 | comment: Single or multiline comment 22 | env: 23 | ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} 24 | ``` 25 | 26 | **_organization_** - _(required)_ name of the organization to which you would like to invite your contributors 27 | 28 | **_team_** - _(optional)_ name of the team within your organization to which you would like to add your contributors 29 | 30 | **_comment_** - _(optional)_ single or multiline _(use yaml syntax)_ comment which will be added, when contributor's first PR gets merged 31 | 32 | **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`_ . 33 | 34 | ## License 35 | 36 | [MIT](LICENSE) 37 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const core = require('@actions/core') 2 | const github = require('@actions/github') 3 | 4 | const transformTeamName = teamName => teamName.toLowerCase().replace(' ', '-') 5 | 6 | const run = async () => { 7 | try { 8 | const organization = core.getInput('organization', { required: true }) 9 | const teamName = core.getInput('team') 10 | const comment = core.getInput('comment') 11 | const { ACCESS_TOKEN } = process.env 12 | 13 | if (!ACCESS_TOKEN) 14 | return core.setFailed('ENV required and not supplied: ACCESS_TOKEN') 15 | 16 | const { payload, sha } = github.context 17 | const { repository } = payload 18 | const octokit = new github.GitHub(ACCESS_TOKEN) 19 | 20 | const commit = await octokit.git.getCommit({ 21 | owner: repository.owner.login, 22 | repo: repository.name, 23 | commit_sha: sha 24 | }) 25 | 26 | const isMergeCommit = commit.data.parents.length > 1 27 | if (!isMergeCommit) return 28 | 29 | const { 30 | data: [pullRequest] 31 | } = await octokit.repos.listPullRequestsAssociatedWithCommit({ 32 | owner: repository.owner.login, 33 | repo: repository.name, 34 | commit_sha: sha 35 | }) 36 | 37 | const contributor = pullRequest.user 38 | 39 | if (teamName) { 40 | const team = await octokit.teams.getByName({ 41 | org: organization, 42 | team_slug: transformTeamName(teamName) 43 | }) 44 | 45 | try { 46 | await octokit.teams.getMembership({ 47 | team_id: team.data.id, 48 | username: contributor.login 49 | }) 50 | } catch (_) { 51 | try { 52 | await octokit.teams.addOrUpdateMembership({ 53 | team_id: team.data.id, 54 | username: contributor.login 55 | }) 56 | 57 | if (comment) 58 | await octokit.issues.createComment({ 59 | owner: repository.owner.login, 60 | repo: repository.name, 61 | issue_number: pullRequest.number, 62 | body: comment 63 | }) 64 | } catch (error) { 65 | core.setFailed(error.message) 66 | } 67 | } 68 | } else { 69 | try { 70 | await octokit.orgs.checkMembership({ 71 | org: organization, 72 | username: contributor.login 73 | }) 74 | } catch (_) { 75 | try { 76 | await octokit.orgs.createInvitation({ 77 | org: organization, 78 | invitee_id: contributor.id 79 | }) 80 | 81 | if (comment) 82 | await octokit.issues.createComment({ 83 | owner: repository.owner.login, 84 | repo: repository.name, 85 | issue_number: pullRequest.number, 86 | body: comment 87 | }) 88 | } catch (error) { 89 | core.setFailed(error.message) 90 | } 91 | } 92 | } 93 | } catch (error) { 94 | core.setFailed(error.message) 95 | } 96 | } 97 | 98 | run() 99 | --------------------------------------------------------------------------------