Skip to content

Commit

Permalink
Merge pull request #6 from smartlyio/put_v4_changes_into_master
Browse files Browse the repository at this point in the history
Bring changes from v4 into master, allowing different repo
  • Loading branch information
mhalmagiu committed May 21, 2021
2 parents 29f2525 + 6ada2b4 commit a49fd46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ inputs:
description: 'Whether the comment should be exclusive or not'
required: false
default: true
repo_name:
description: 'Repo name in the format: smartlyio/test-repo. Defaults to current Repo.'
required: false
default: ${{ github.repository }}
pr_number:
description: 'PR number. Defaults to current PR'
required: false
default: ${{ github.event.pull_request.number }}
runs:
using: 'node12'
main: 'dist/index.js'
23 changes: 12 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const core = require('@actions/core');
const github = require('@actions/github');

async function getAllComments(client, pullRequest, comment) {
async function getAllComments(client, owner, repo, issue_number) {
try {
const allComments = await client.issues.listComments({
owner: pullRequest.owner,
repo: pullRequest.repo,
issue_number: pullRequest.number
owner,
repo,
issue_number
});
const returnComments = allComments.data.map(a => a.body);
return returnComments;
Expand All @@ -15,12 +15,12 @@ async function getAllComments(client, pullRequest, comment) {
}
}

async function addComment(client, pullRequest, comment) {
async function addComment(client, owner, repo, issue_number, comment) {
try {
await client.issues.createComment({
owner: pullRequest.owner,
repo: pullRequest.repo,
issue_number: pullRequest.number,
owner,
repo,
issue_number,
body: comment
});
} catch (error) {
Expand All @@ -33,17 +33,18 @@ async function run ()
// Get client and context
const client = new github.GitHub(core.getInput('GITHUB_TOKEN'));
const context = github.context;
const pullRequest = context.issue;
const [owner, repo] = core.getInput('repo_name').split('/');
const issue_number = core.getInput('pr_number');
const comment = core.getInput('comment');
const exclusive = core.getInput('exclusive');

const allComments = await getAllComments(client, pullRequest)
const allComments = await getAllComments(client, owner, repo, issue_number)

if (allComments.includes(comment) && exclusive) {
console.log("COMMENT ALREADY EXISTS.")
console.log("Not adding a second time")
} else {
addComment(client, pullRequest, comment);
addComment(client, owner, repo, issue_number, comment);
}
}

Expand Down

0 comments on commit a49fd46

Please sign in to comment.