Safe nullish check with git-url-parse library responses

This commit is contained in:
Himanshu Mishra
2021-01-18 23:04:31 +01:00
parent baeed36324
commit 380dd626fb
3 changed files with 6 additions and 6 deletions
@@ -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.
+4 -4
View File
@@ -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');
}