Skip to content

Commit

Permalink
Github Actions: Issue Assigned Check (#93)
Browse files Browse the repository at this point in the history
* ignore editor folder

* move check issue labels to oppiabot

* build actions

* split up the pr

* create actions build test file and setup ci for it

* modify CI config

* update dist

* setup hooks

* testing hooks

* testing hooks

* build only when actions file changes

* testing hooks

* remove test comment

* modify lint-staged

* another test

* another test

* still testing

* final testing

* remove actions build test from ci

* address review comments

* address review comments

* initial work here

* create check

* more on this

* add tests

* fixed bug

* remove unneeded file

* address review comments

* address review comments

* address review comments
  • Loading branch information
jameesjohn authored Jun 25, 2020
1 parent ae99bee commit 852a0dc
Show file tree
Hide file tree
Showing 8 changed files with 342,576 additions and 24,030 deletions.
6 changes: 6 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ inputs:
repo-token: # Repository token.
description: 'The repository token needed to create comments.'
required: true
google-api-key:
description: 'API credential for accessing google apis.'
required: true
cla-sheet-id:
description: 'ID for the CLA spreadsheet.'
required: true

runs:
using: "node12"
Expand Down
10 changes: 4 additions & 6 deletions actions/src/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
const core = require('@actions/core');
const { context } = require('@actions/github');
const issueLabelsModule = require('./issues/checkIssueLabels');
const checkIssueAssigneeModule = require('./issues/checkIssueAssignee');
const constants = require('../../constants');

const EVENTS = {
ISSUES: 'issues',
};
const ACTIONS = {
LABELLED: 'labeled'
};
module.exports = {
async dispatch(event, action) {
core.info(`Received Event:${event} Action:${action}.`);
Expand All @@ -42,6 +37,9 @@ module.exports = {
case constants.issuesLabelCheck:
await issueLabelsModule.checkLabels();
break;
case constants.issuesAssignedCheck:
await checkIssueAssigneeModule.checkAssignees();
break;
}
}
}
Expand Down
89 changes: 89 additions & 0 deletions actions/src/issues/checkIssueAssignee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// Copyright 2020 The Oppia Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @fileoverview Handler to check issue assigned event.
*/

const core = require('@actions/core');
const { context, GitHub } = require('@actions/github');
const { google } = require('googleapis');

const checkAssignees = async () => {
core.info('A USER GOT ASSIGNED TO AN ISSUE...');
const token = core.getInput('repo-token');
const octokit = new GitHub(token);
const assignee = context.payload.assignee;
const issue = context.payload.issue;
const linkToCla = 'here'.link(
'https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia#setting-things-up');

// Catch and log any error that will occur while accessing google sheets api.
try {
core.info('Checking if ' + assignee.login + ' has signed the CLA');
const assigneeHasSignedCla = await hasSignedCla(assignee.login);
if (!assigneeHasSignedCla) {
core.info(assignee.login + ' has not signed the CLA');

const commentBody = 'Hi @' + assignee.login + ', you need to sign the ' +
'CLA before you can get assigned to issues. Follow the instructions ' +
linkToCla + ' to get started. Thanks!';

await octokit.issues.createComment({
issue_number: issue.number,
repo: context.repo.repo,
owner: context.repo.owner,
body: commentBody,
});

await octokit.issues.removeAssignees({
issue_number: issue.number,
repo: context.repo.repo,
owner: context.repo.owner,
assignees: [assignee.login],
});
}
} catch (error) {
core.setFailed(error);
}

};

/**
* Checks that a user has signed the CLA.
*
* @param {String} username - Username of the user that added the label.
* @param {import('@actions/github').GitHub} octokit
*/
const hasSignedCla = async (username) => {
const GOOGLE_API_KEY = core.getInput('google-api-key');
const CLA_SHEET_ID = core.getInput('cla-sheet-id');

const sheets = google.sheets('v4');
const rows = await sheets.spreadsheets.values.get({
auth: GOOGLE_API_KEY,
spreadsheetId: CLA_SHEET_ID,
range: 'Usernames!A:A',
});

const hasUserSignedCla = rows.data.values.some(row => {
return row[0].toLowerCase() === username.toLowerCase();
});

return hasUserSignedCla;
};

module.exports = {
checkAssignees,
};
Loading

0 comments on commit 852a0dc

Please sign in to comment.