diff --git a/.github/workflows/community.yml b/.github/workflows/community.yml index db39b5f..7660aa8 100644 --- a/.github/workflows/community.yml +++ b/.github/workflows/community.yml @@ -1,8 +1,14 @@ on: issues: types: [ opened ] + issue_comment: + types: [ created ] pull_request: types: [ opened ] + pull_request_review: + types: [ submitted ] + pull_request_review_comment: + types: [ created ] jobs: welcome: @@ -13,6 +19,7 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} issue-message: '# Congratulations :tada:\nThis is your first **Issue**! Welcome to the community :nerd:' pr-message: '# Congratulations :tada:\nThis is your first **Pull Request**! Welcome to the community :nerd:' - - uses: EddieJaoudeCommunity/gh-action-community@v0.1 + - uses: EddieJaoudeCommunity/gh-action-community@eddiejaoude-issue-18 with: github-token: ${{ secrets.GITHUB_TOKEN }} + firebase-ket: ${{ secrets.FIREBASE_KEY }} diff --git a/action.yml b/action.yml index a1ac638..efe9f1a 100644 --- a/action.yml +++ b/action.yml @@ -4,6 +4,9 @@ inputs: github-token: description: 'GitHub token for repo' required: true + firebase-key: + description: 'Firebase key' + required: true runs: using: 'node12' - main: 'index.js' + main: 'src/index.js' diff --git a/index.js b/index.js deleted file mode 100644 index ba51f62..0000000 --- a/index.js +++ /dev/null @@ -1,12 +0,0 @@ -const core = require('@actions/core'); -const github = require('@actions/github'); - -(async () => { - try { - // const githubSecret = core.getInput('github-token', { required: true }); - - console.log('HERE'); - } catch (error) { - core.setFailed(error.message); - } -})(); diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..36d2af5 --- /dev/null +++ b/src/index.js @@ -0,0 +1,25 @@ +const core = require('@actions/core'); +const github = require('@actions/github'); +const admin = require('firebase-admin'); + +(async () => { + try { + const firebaseKey = core.getInput('firebase-key', { required: true }); + + admin.initializeApp({ + credential: admin.credential.cert(JSON.parse(firebaseKey)), + }); + + const db = admin.firestore(); + const author = github.context.payload.sender; + const type = process.env.GITHUB_EVENT_NAME; + + const docRef = db.collection('usersGitHub').doc(author.id); + await docRef.set({ + ...author, + type: admin.firestore.FieldValue.increment(1) + }, { merge: true }); + } catch (error) { + core.setFailed(error.message); + } +})();