Skip to content

Commit

Permalink
Merge pull request #26 from vj-abigo/error-message
Browse files Browse the repository at this point in the history
feat: show  message for existing members
  • Loading branch information
vj-abishek authored Jan 19, 2022
2 parents 6483278 + 39c5f82 commit 2b28133
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 12 deletions.
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: invite-on-label
description: Send invitation based on issue
description: Send invitation based on issue label
author: Abishek P.Y
branding:
icon: anchor
Expand All @@ -18,6 +18,10 @@ inputs:
description: A comment which will be posted on the issue.
required: false
default: Invitation sent for the GitHub Organisation. Welcome to the community
existingMemberMessage:
description: Message for existing organisation members
required: false
default: You are already the member of our Organisation.
runs:
using: node12
main: dist/index.js
22 changes: 17 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ const core = __nccwpck_require__(186);
const github = __nccwpck_require__(438);

const main = async () => {

const repoToken = core.getInput('repo-token', { required: true });
const client = github.getOctokit(repoToken);
const { payload } = github.context;
const existingMemberMessage = core.getInput('existingMemberMessage')

try {
const { INVITE_TOKEN } = process.env;
const repoToken = core.getInput('repo-token', { required: true });

if (!INVITE_TOKEN) {
return core.setFailed('ENV required and not supplied: INVITE_TOKEN');
}
const octokit = github.getOctokit(INVITE_TOKEN);
const client = github.getOctokit(repoToken);

const { payload } = github.context;
const inviteeId = payload.issue.user.id;
const currentLabel = payload.label.name;

Expand All @@ -40,15 +43,13 @@ const main = async () => {
});
core.info('Invitation sent successfully 🎉🎉');

core.info('Adding a comment before closing the issue');
await client.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
body: comment,
});

core.info('Closing the issue');
await client.issues.update({
owner: payload.repository.owner.login,
repo: payload.repository.name,
Expand All @@ -58,6 +59,17 @@ const main = async () => {
}
}
} catch (error) {

if (error.message.toString().includes('already a part')) {
await client.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
body: existingMemberMessage,
state: 'closed',
});
}

return core.setFailed(error.message);
}
return core.setOutput('Invitation sent successfully 🎉🎉');
Expand Down
22 changes: 17 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ const core = require('@actions/core');
const github = require('@actions/github');

const main = async () => {

const repoToken = core.getInput('repo-token', { required: true });
const client = github.getOctokit(repoToken);
const { payload } = github.context;
const existingMemberMessage = core.getInput('existingMemberMessage')

try {
const { INVITE_TOKEN } = process.env;
const repoToken = core.getInput('repo-token', { required: true });

if (!INVITE_TOKEN) {
return core.setFailed('ENV required and not supplied: INVITE_TOKEN');
}
const octokit = github.getOctokit(INVITE_TOKEN);
const client = github.getOctokit(repoToken);

const { payload } = github.context;
const inviteeId = payload.issue.user.id;
const currentLabel = payload.label.name;

Expand All @@ -33,15 +36,13 @@ const main = async () => {
});
core.info('Invitation sent successfully 🎉🎉');

core.info('Adding a comment before closing the issue');
await client.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
body: comment,
});

core.info('Closing the issue');
await client.issues.update({
owner: payload.repository.owner.login,
repo: payload.repository.name,
Expand All @@ -51,6 +52,17 @@ const main = async () => {
}
}
} catch (error) {

if (error.message.toString().includes('already a part')) {
await client.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: payload.issue.number,
body: existingMemberMessage,
state: 'closed',
});
}

return core.setFailed(error.message);
}
return core.setOutput('Invitation sent successfully 🎉🎉');
Expand Down
1 change: 0 additions & 1 deletion package-lock.json

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

0 comments on commit 2b28133

Please sign in to comment.