-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes unit tests by uncoupling dependencies
(#3621)
- Loading branch information
Showing
5 changed files
with
47 additions
and
45 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/git/models/__tests__/pullRequest.test.ts → ...odels/__tests__/pullRequest.utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// pullRequest.ts pulls many dependencies through Container and some of them break the unit tests. | ||
// To avoid this file has been created that can collect more simple functions which | ||
// don't require Container and can be tested. | ||
|
||
export type PullRequestURLIdentity = { | ||
ownerAndRepo?: string; | ||
prNumber?: string; | ||
}; | ||
|
||
export function getPullRequestIdentityValuesFromSearch(search: string): PullRequestURLIdentity { | ||
let ownerAndRepo: string | undefined = undefined; | ||
let prNumber: string | undefined = undefined; | ||
|
||
let match = search.match(/([^/]+\/[^/]+)\/pull\/(\d+)/); // with org and rep name | ||
if (match != null) { | ||
ownerAndRepo = match[1]; | ||
prNumber = match[2]; | ||
} | ||
|
||
if (prNumber == null) { | ||
match = search.match(/(?:\/|^)pull\/(\d+)/); // without repo name | ||
if (match != null) { | ||
prNumber = match[1]; | ||
} | ||
} | ||
|
||
if (prNumber == null) { | ||
match = search.match(/(?:\/)(\d+)/); // any number starting with "/" | ||
if (match != null) { | ||
prNumber = match[1]; | ||
} | ||
} | ||
|
||
if (prNumber == null) { | ||
match = search.match(/^#?(\d+)$/); // just a number or with a leading "#" | ||
if (match != null) { | ||
prNumber = match[1]; | ||
} | ||
} | ||
|
||
return { ownerAndRepo: ownerAndRepo, prNumber: prNumber }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters