Skip to content

Commit

Permalink
Merge branch 'main' into marcaaron-addOnfidoSDKs
Browse files Browse the repository at this point in the history
  • Loading branch information
tgolen committed Jun 2, 2021
2 parents 77abcee + b69f793 commit 215f1e4
Show file tree
Hide file tree
Showing 42 changed files with 658 additions and 218 deletions.
12 changes: 9 additions & 3 deletions .github/actions/getMergeCommitForPullRequest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@ name: 'Get merge commit for a pull request'
description: 'Get the merge_commit_sha for a pull request'
inputs:
GITHUB_TOKEN:
description: 'Github token for authentication'
description: Auth token for Expensify.cash Github
required: true
PULL_REQUEST_NUMBER:
description: 'The number of the pull request'
required: true
description: The number of the pull request
required: false
TITLE_REGEX:
description: Regex to match PR titles for
required: false
USER:
description: The creator of the pull request
required: false
outputs:
MERGE_COMMIT_SHA:
description: 'The merge_commit_sha of the given pull request'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,66 @@
const _ = require('underscore');
const core = require('@actions/core');
const ActionUtils = require('../../libs/ActionUtils');
const GithubUtils = require('../../libs/GithubUtils');

const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: true});
console.log(`Getting merge_commit_sha for PR #${pullRequestNumber}`);
GithubUtils.octokit.pulls.get({
const DEFAULT_PAYLOAD = {
owner: GithubUtils.GITHUB_OWNER,
repo: GithubUtils.EXPENSIFY_CASH_REPO,
pull_number: pullRequestNumber,
})
.then(({data}) => {
const mergeCommitHash = data.merge_commit_sha;
if (mergeCommitHash) {
console.log(`PR #${pullRequestNumber} has merge_commit_sha ${mergeCommitHash}`);
core.setOutput('MERGE_COMMIT_SHA', mergeCommitHash);
} else {
const err = new Error(`Could not find merge_commit_sha for pull request ${pullRequestNumber}`);
console.error(err);
core.setFailed(err);
}
})
.catch((err) => {
console.log(`An unknown error occurred with the GitHub API: ${err}`);
};

const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: false}, null);
const user = ActionUtils.getJSONInput('USER', {required: false}, null);
const titleRegex = ActionUtils.getJSONInput('TITLE_REGEX', {required: false}, null);

if (pullRequestNumber) {
console.log(`Looking for pull request w/ number: ${pullRequestNumber}`);
}

if (user) {
console.log(`Looking for pull request w/ user: ${user}`);
}

if (titleRegex) {
console.log(`Looking for pull request w/ title matching: ${titleRegex.toString()}`);
}

/**
* Process a pull request and outputs it's merge commit hash.
*
* @param {Object} PR
*/
function outputMergeCommitHash(PR) {
if (!_.isEmpty(PR)) {
console.log(`Found matching pull request: ${PR.html_url}`);
core.setOutput('MERGE_COMMIT_SHA', PR.merge_commit_sha);
} else {
const err = new Error('Could not find matching pull request');
console.error(err);
core.setFailed(err);
});
}
}

/**
* Handle an unknown API error.
*
* @param {Error} err
*/
function handleUnknownError(err) {
console.log(`An unknown error occurred with the GitHub API: ${err}`);
core.setFailed(err);
}

if (pullRequestNumber) {
GithubUtils.octokit.pulls.get({
...DEFAULT_PAYLOAD,
pull_number: pullRequestNumber,
})
.then(({data}) => outputMergeCommitHash(data))
.catch(handleUnknownError);
} else {
GithubUtils.octokit.pulls.list(DEFAULT_PAYLOAD)
.then(({data}) => {
const matchingPR = _.find(data, PR => PR.user.login === user && titleRegex.test(PR.title));
outputMergeCommitHash(matchingPR);
});
}
78 changes: 59 additions & 19 deletions .github/actions/getMergeCommitForPullRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,72 @@ module.exports =
/***/ 265:
/***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => {

const _ = __nccwpck_require__(4987);
const core = __nccwpck_require__(2186);
const ActionUtils = __nccwpck_require__(970);
const GithubUtils = __nccwpck_require__(7999);

const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: true});
console.log(`Getting merge_commit_sha for PR #${pullRequestNumber}`);
GithubUtils.octokit.pulls.get({
const DEFAULT_PAYLOAD = {
owner: GithubUtils.GITHUB_OWNER,
repo: GithubUtils.EXPENSIFY_CASH_REPO,
pull_number: pullRequestNumber,
})
.then(({data}) => {
const mergeCommitHash = data.merge_commit_sha;
if (mergeCommitHash) {
console.log(`PR #${pullRequestNumber} has merge_commit_sha ${mergeCommitHash}`);
core.setOutput('MERGE_COMMIT_SHA', mergeCommitHash);
} else {
const err = new Error(`Could not find merge_commit_sha for pull request ${pullRequestNumber}`);
console.error(err);
core.setFailed(err);
}
})
.catch((err) => {
console.log(`An unknown error occurred with the GitHub API: ${err}`);
};

const pullRequestNumber = ActionUtils.getJSONInput('PULL_REQUEST_NUMBER', {required: false}, null);
const user = ActionUtils.getJSONInput('USER', {required: false}, null);
const titleRegex = ActionUtils.getJSONInput('TITLE_REGEX', {required: false}, null);

if (pullRequestNumber) {
console.log(`Looking for pull request w/ number: ${pullRequestNumber}`);
}

if (user) {
console.log(`Looking for pull request w/ user: ${user}`);
}

if (titleRegex) {
console.log(`Looking for pull request w/ title matching: ${titleRegex.toString()}`);
}

/**
* Process a pull request and outputs it's merge commit hash.
*
* @param {Object} PR
*/
function outputMergeCommitHash(PR) {
if (!_.isEmpty(PR)) {
console.log(`Found matching pull request: ${PR.html_url}`);
core.setOutput('MERGE_COMMIT_SHA', PR.merge_commit_sha);
} else {
const err = new Error('Could not find matching pull request');
console.error(err);
core.setFailed(err);
});
}
}

/**
* Handle an unknown API error.
*
* @param {Error} err
*/
function handleUnknownError(err) {
console.log(`An unknown error occurred with the GitHub API: ${err}`);
core.setFailed(err);
}

if (pullRequestNumber) {
GithubUtils.octokit.pulls.get({
...DEFAULT_PAYLOAD,
pull_number: pullRequestNumber,
})
.then(({data}) => outputMergeCommitHash(data))
.catch(handleUnknownError);
} else {
GithubUtils.octokit.pulls.list(DEFAULT_PAYLOAD)
.then(({data}) => {
const matchingPR = _.find(data, PR => PR.user.login === user && titleRegex.test(PR.title));
outputMergeCommitHash(matchingPR);
});
}


/***/ }),
Expand Down
49 changes: 46 additions & 3 deletions .github/actions/markPullRequestsAsDeployed/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports =
/***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => {

const core = __nccwpck_require__(2186);
const {GitHub} = __nccwpck_require__(3030);
const {context} = __nccwpck_require__(5438);
const ActionUtils = __nccwpck_require__(970);
const GithubUtils = __nccwpck_require__(7999);

Expand Down Expand Up @@ -56,11 +56,11 @@ message += `\n🍎 iOS 🍎|${iOSResult} \n🕸 web 🕸|${webResult}`;
/**
* Comment Single PR
*
* @param {Object} pr
* @param {Number} pr
* @returns {Promise<void>}
*/
function commentPR(pr) {
return GithubUtils.createComment(GitHub.context.repo.repo, pr, message)
return GithubUtils.createComment(context.repo.repo, pr, message)
.then(() => {
console.log(`Comment created on #${pr} successfully 🎉`);
})
Expand Down Expand Up @@ -1011,6 +1011,49 @@ exports.Context = Context;

/***/ }),

/***/ 5438:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

"use strict";

var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getOctokit = exports.context = void 0;
const Context = __importStar(__nccwpck_require__(4087));
const utils_1 = __nccwpck_require__(3030);
exports.context = new Context.Context();
/**
* Returns a hydrated octokit ready to use for GitHub Actions
*
* @param token the repo PAT or GITHUB_TOKEN
* @param options other options to set
*/
function getOctokit(token, options) {
return new utils_1.GitHub(utils_1.getOctokitOptions(token, options));
}
exports.getOctokit = getOctokit;
//# sourceMappingURL=github.js.map

/***/ }),

/***/ 7914:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const core = require('@actions/core');
const {GitHub} = require('@actions/github/lib/utils');
const {context} = require('@actions/github');
const ActionUtils = require('../../libs/ActionUtils');
const GithubUtils = require('../../libs/GithubUtils');

Expand Down Expand Up @@ -46,11 +46,11 @@ message += `\n🍎 iOS 🍎|${iOSResult} \n🕸 web 🕸|${webResult}`;
/**
* Comment Single PR
*
* @param {Object} pr
* @param {Number} pr
* @returns {Promise<void>}
*/
function commentPR(pr) {
return GithubUtils.createComment(GitHub.context.repo.repo, pr, message)
return GithubUtils.createComment(context.repo.repo, pr, message)
.then(() => {
console.log(`Comment created on #${pr} successfully 🎉`);
})
Expand Down
Loading

0 comments on commit 215f1e4

Please sign in to comment.