Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
fix(fork): custom comments action #25
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiejaoude committed Sep 6, 2020
1 parent 878fd72 commit ab30aca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/community.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ jobs:
welcome:
runs-on: ubuntu-latest
steps:
- uses: actions/first-interaction@v1
- uses: EddieJaoudeCommunity/gh-action-community@main
if: ${{ github.repository_owner == 'EddieJaoudeCommunity' }}
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
issue-message: '<h1>Congratulations :tada:</h1>This is your first <strong>Issue</strong>! Welcome to the community :nerd_face:'
pr-message: '<h1>Congratulations :tada:</h1>This is your first <strong>Pull Request</strong>! Welcome to the community :nerd_face:'

Expand Down
44 changes: 39 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ const admin = require('firebase-admin');

(async () => {
try {
const githubToken = core.getInput('github-token', { required: true });
const firebaseKey = core.getInput('firebase-key', { required: true });
const issueMessage = core.getInput('issue-message');
const prMessage = core.getInput('pr-message');

// save statistics to db
admin.initializeApp({
credential: admin.credential.cert(JSON.parse(firebaseKey)),
});
Expand All @@ -15,11 +19,41 @@ const admin = require('firebase-admin');
const type = process.env.GITHUB_EVENT_NAME;

const docRef = db.collection('usersGitHub').doc(author.id.toString());
await docRef.set({
author,
id: author.id.toString(),
[type]: admin.firestore.FieldValue.increment(1),
}, { merge: true });
await docRef.set(
{
author,
id: author.id.toString(),
[type]: admin.firestore.FieldValue.increment(1),
},
{ merge: true }
);

// add a comment to the issue or pull request
// @TODO: with a markdown sheild / badge
const client = new github.GitHub(githubToken);
const context = github.context;

if (context.payload.action !== 'opened') {
console.log('No issue / pull request was opened, skipping');
return;
}

if (!!context.payload.issue) {
await client.issues.createComment({
owner: context.issue.owner,
repo: context.issue.repo,
issue_number: contextissue.number,
body: issueMessage
});
} else {
await client.pulls.createReview({
owner: context.issue.owner,
repo: context.issue.repo,
pull_number: context.issue.number,
body: prMessage,
event: 'COMMENT'
});
}
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit ab30aca

Please sign in to comment.