Skip to content

Commit

Permalink
fix: Do not throw err if cannot get changed files or get opened prs
Browse files Browse the repository at this point in the history
  • Loading branch information
tkyi committed Sep 30, 2019
1 parent fc7cde9 commit aa141d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
18 changes: 11 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ class GithubScm extends Scm {
}));
} catch (err) {
winston.error('Failed to getOpenedPRs: ', err);
throw err;

return [];
}
}

Expand Down Expand Up @@ -566,7 +567,7 @@ class GithubScm extends Scm {

/**
* Get a users permissions on an organization
* @method getOrgPermissions
* @method _getOrgPermissions
* @param {Object} config Configuration
* @param {String} config.organization The organization to get permissions on
* @param {String} config.username The user to check against
Expand Down Expand Up @@ -651,7 +652,7 @@ class GithubScm extends Scm {

/**
* Get a commit sha from a reference
* @async getCommitRefSha
* @async _getCommitRefSha
* @param {Object} config
* @param {String} config.token The token used to authenticate to the SCM
* @param {String} config.owner The owner of the target repository
Expand Down Expand Up @@ -1029,7 +1030,8 @@ class GithubScm extends Scm {
return files.map(file => file.filename);
} catch (err) {
winston.error('Failed to getChangedFiles: ', err);
throw err;

return [];
}
}

Expand Down Expand Up @@ -1236,8 +1238,9 @@ class GithubScm extends Scm {

/**
* Resolve a pull request object based on the config
* @async getPrRef
* @async _getPrInfo
* @param {Object} config
* @param {Object} [config.scmRepo] The SCM repository to look up
* @param {String} config.scmUri The scmUri to get PR info of
* @param {String} config.token The token used to authenticate to the SCM
* @param {Integer} config.prNum The PR number used to fetch the PR
Expand Down Expand Up @@ -1286,6 +1289,7 @@ class GithubScm extends Scm {

/**
* Add a PR comment
* @async _addPrComment
* @param {Object} config
* @param {String} config.comment The PR comment
* @param {Integer} config.prNum The PR number
Expand Down Expand Up @@ -1326,7 +1330,7 @@ class GithubScm extends Scm {

/**
* Get an array of scm context (e.g. github:github.com)
* @method getScmContexts
* @method _getScmContexts
* @return {Array} Array of scm contexts
*/
_getScmContexts() {
Expand All @@ -1339,7 +1343,7 @@ class GithubScm extends Scm {

/**
* Determine if an scm module can handle the received webhook
* @async canHandleWebhook
* @async _canHandleWebhook
* @param {Object} headers The request headers associated with the webhook payload
* @param {Object} payload The webhook payload received from the SCM service
* @return {Promise} Resolves a boolean denoting whether scm module supports webhook
Expand Down
24 changes: 13 additions & 11 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,7 @@ jobs:
});
});

it('rejects when failing to communicate with github', () => {
it('returns empty array when failing to communicate with github', () => {
const testError = new Error('someGithubCommError');

type = 'pr';
Expand All @@ -1150,11 +1150,8 @@ jobs:
type,
token,
payload: testPayloadOpen
}).then(() => {
assert.fail('This should not fail the test');
}, (err) => {
assert.deepEqual(err, testError);

}).then((result) => {
assert.deepEqual(result, []);
assert.calledWith(githubMock.paginate,
'GET /repos/:owner/:repo/pulls/:number/files', {
owner: 'baxterthehacker',
Expand Down Expand Up @@ -2005,7 +2002,7 @@ jobs:
});
});

describe('_getOpenedPRs', () => {
describe('getOpenedPRs', () => {
const scmUri = 'github.com:111:branchName';
const config = {
scmUri,
Expand Down Expand Up @@ -2084,14 +2081,19 @@ jobs:
});
});

it('rejects when failing to fetch opened pull requests', () => {
it('returns empty array when failing to fetch opened pull requests', () => {
const testError = new Error('testError');

githubMock.pulls.list.rejects(testError);

return scm._getOpenedPRs(config).then(assert.fail, (err) => {
assert.instanceOf(err, Error);
assert.strictEqual(testError.message, err.message);
return scm._getOpenedPRs(config).then((data) => {
assert.calledWith(githubMock.request, 'GET /repositories/:id', { id: '111' });
assert.calledWith(githubMock.pulls.list, {
owner: 'repoOwner',
repo: 'repoName',
state: 'open'
});
assert.deepEqual(data, []);
});
});
});
Expand Down

0 comments on commit aa141d0

Please sign in to comment.