Skip to content

Commit

Permalink
Add support for private repos
Browse files Browse the repository at this point in the history
  • Loading branch information
rahularya50 committed Feb 7, 2021
1 parent 470b3ce commit 394cbbe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
23 changes: 16 additions & 7 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const { GitHub, context } = require('@actions/github');
const parse = require('parse-diff');
const github_1 = require("@actions/github");
const parse_diff_1 = __importDefault(require("parse-diff"));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const token = core.getInput('github-token', { required: true });
const github = new GitHub(token, {});
const github = new github_1.GitHub(token, {});
const keyword = core.getInput('keyword');
const diff_url = context.payload.pull_request.diff_url;
const result = yield github.request(diff_url);
const files = parse(result.data);
const url = github_1.context.payload.pull_request.url;
const result = yield github.request(url, {
headers: {
Accept: 'application/vnd.github.v3.diff'
}
});
const files = parse_diff_1.default(result.data);
core.exportVariable('files', files);
core.setOutput('files', files);
let changes = '';
for (const file of files) {
for (const chunk of file.chunks) {
for (const change of chunk.changes) {
if (change.add) {
if (change.type === 'add') {
changes += change.content;
}
}
Expand All @@ -57,6 +64,8 @@ function run() {
}
}
catch (error) {
console.error(error.stack);
console.error(error);
core.setFailed(error.message);
}
});
Expand Down
16 changes: 11 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import * as core from '@actions/core'
const {GitHub, context} = require('@actions/github')
const parse = require('parse-diff')
import {GitHub, context} from '@actions/github'
import parse from 'parse-diff'

async function run() {
try {
const token = core.getInput('github-token', {required: true})
const github = new GitHub(token, {})
const keyword = core.getInput('keyword')

const diff_url = context.payload.pull_request.diff_url
const result = await github.request(diff_url)
const url = context.payload.pull_request.url
const result = await github.request(url, {
headers: {
Accept: 'application/vnd.github.v3.diff'
}
})
const files = parse(result.data)
core.exportVariable('files', files)
core.setOutput('files', files)
Expand All @@ -18,7 +22,7 @@ async function run() {
for (const file of files) {
for (const chunk of file.chunks) {
for (const change of chunk.changes) {
if (change.add) {
if (change.type === 'add') {
changes += change.content
}
}
Expand All @@ -29,6 +33,8 @@ async function run() {
core.setFailed(`The code contains ${keyword}`)
}
} catch (error) {
console.error( error.stack )
console.error(error)
core.setFailed(error.message)
}
}
Expand Down

0 comments on commit 394cbbe

Please sign in to comment.