Safe nullish check with git-url-parse library responses
This commit is contained in:
@@ -130,7 +130,7 @@ export class GithubUrlReader implements UrlReader {
|
||||
|
||||
// ref is an empty string if no branch is set in provided url to readTree.
|
||||
// Use GitHub API to get the default branch of the repository.
|
||||
const branch = ref === '' ? repoResponseJson.default_branch : ref;
|
||||
const branch = ref || repoResponseJson.default_branch;
|
||||
const branchesApiUrl = repoResponseJson.branches_url;
|
||||
|
||||
// Fetch the latest commit in the provided or default branch to compare against
|
||||
|
||||
@@ -99,7 +99,7 @@ export class GitlabUrlReader implements UrlReader {
|
||||
const projectGitlabResponseJson = await projectGitlabResponse.json();
|
||||
|
||||
// ref is an empty string if no branch is set in provided url to readTree.
|
||||
const branch = ref === '' ? projectGitlabResponseJson.default_branch : ref;
|
||||
const branch = ref || projectGitlabResponseJson.default_branch;
|
||||
|
||||
// Fetch the latest commit in the provided or default branch to compare against
|
||||
// the provided sha.
|
||||
|
||||
@@ -129,11 +129,11 @@ export function getAzureCommitsUrl(url: string): string {
|
||||
const ref = parsedUrl.searchParams.get('version')?.substr(2);
|
||||
|
||||
if (
|
||||
empty !== '' ||
|
||||
userOrOrg === '' ||
|
||||
project === '' ||
|
||||
!!empty ||
|
||||
!userOrOrg ||
|
||||
!project ||
|
||||
srcKeyword !== '_git' ||
|
||||
repoName === ''
|
||||
!repoName
|
||||
) {
|
||||
throw new Error('Wrong Azure Devops URL');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user