-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(1769): Do not throw err if cannot get changed files #142
Conversation
index.js
Outdated
@@ -478,7 +478,7 @@ class GithubScm extends Scm { | |||
|
|||
/** | |||
* Get a list of names and references of opened PRs | |||
* @async _getOpenedPRs | |||
* @async getOpenedPRs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, _getOpenedPRs
and _ getChangedFiles
are the function names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not really consistent in the file 🤷♀
index.js
Outdated
@@ -1236,8 +1238,9 @@ class GithubScm extends Scm { | |||
|
|||
/** | |||
* Resolve a pull request object based on the config | |||
* @async getPrRef | |||
* @async getPrInfo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_getPrInfo
index.js
Outdated
@@ -513,7 +513,8 @@ class GithubScm extends Scm { | |||
})); | |||
} catch (err) { | |||
winston.error('Failed to getOpenedPRs: ', err); | |||
throw err; | |||
|
|||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are not returning the error, then we can return [];
in finally block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong about the previous comment. Return in finally
block always override the return value in try
block.
Maybe we can write something like
let pullRequests = [];
try {
pullRequests = await this.breaker.runCommand({ const pullRequests = await this.breaker.runCommand({
action: 'list', action: 'list',
scopeType: 'pulls', scopeType: 'pulls',
token, token,
params: { params: {
owner, owner,
repo, repo,
state: 'open' state: 'open'
} }
}); });
return pullRequests.data.map(pullRequest => ({ return pullRequests.data.map(pullRequest => ({
name: `PR-${pullRequest.number}`, name: `PR-${pullRequest.number}`,
ref: `pull/${pullRequest.number}/merge`, ref: `pull/${pullRequest.number}/merge`,
username: pullRequest.user.login, username: pullRequest.user.login,
title: pullRequest.title, title: pullRequest.title,
createTime: pullRequest.created_at, createTime: pullRequest.created_at,
url: pullRequest.html_url, url: pullRequest.html_url,
userProfile: pullRequest.user.html_url userProfile: pullRequest.user.html_url
})); }));
} catch (err) {
winston.error('Failed to getOpenedPRs: ', err); winston.error('Failed to getOpenedPRs: ', err);
// throw err;
} finally {
return pullRequests;
}
Have a default value. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better practice not to do return
in finally
getting eslint error no-unsafe-finally
when I try your suggestion
https://eslint.org/docs/rules/no-unsafe-finally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Lets return in catch.
index.js
Outdated
@@ -513,7 +513,8 @@ class GithubScm extends Scm { | |||
})); | |||
} catch (err) { | |||
winston.error('Failed to getOpenedPRs: ', err); | |||
throw err; | |||
|
|||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong about the previous comment. Return in finally
block always override the return value in try
block.
Maybe we can write something like
let pullRequests = [];
try {
pullRequests = await this.breaker.runCommand({ const pullRequests = await this.breaker.runCommand({
action: 'list', action: 'list',
scopeType: 'pulls', scopeType: 'pulls',
token, token,
params: { params: {
owner, owner,
repo, repo,
state: 'open' state: 'open'
} }
}); });
return pullRequests.data.map(pullRequest => ({ return pullRequests.data.map(pullRequest => ({
name: `PR-${pullRequest.number}`, name: `PR-${pullRequest.number}`,
ref: `pull/${pullRequest.number}/merge`, ref: `pull/${pullRequest.number}/merge`,
username: pullRequest.user.login, username: pullRequest.user.login,
title: pullRequest.title, title: pullRequest.title,
createTime: pullRequest.created_at, createTime: pullRequest.created_at,
url: pullRequest.html_url, url: pullRequest.html_url,
userProfile: pullRequest.user.html_url userProfile: pullRequest.user.html_url
})); }));
} catch (err) {
winston.error('Failed to getOpenedPRs: ', err); winston.error('Failed to getOpenedPRs: ', err);
// throw err;
} finally {
return pullRequests;
}
Have a default value. 🤔
index.js
Outdated
@@ -513,7 +513,8 @@ class GithubScm extends Scm { | |||
})); | |||
} catch (err) { | |||
winston.error('Failed to getOpenedPRs: ', err); | |||
throw err; | |||
|
|||
return []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Lets return in catch.
Context
Sometimes when there are PRs with over 2500 files changed, the webhook will fail since the circuit breaker will timeout.
Objective
This PR does not throw errs when
getChangedFiles
orgetOpenedPrs
calls fail.References
Short term fix for: screwdriver-cd/screwdriver#1769
License
I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.