MCPcopy
hub / github.com/danger/danger-js / pullRequestParser

Function pullRequestParser

source/platforms/pullRequestParser.ts:14–61  ·  view source on GitHub ↗
(address: string)

Source from the content-addressed store, hash-verified

12}
13
14export function pullRequestParser(address: string): PullRequestParts | null {
15 const components = url.parse(address, false)
16
17 if (components && components.path) {
18 // shape: http://localhost:7990/projects/PROJ/repos/repo/pull-requests/1/overview
19 const parts = components.path.match(/(projects\/~?\w+\/repos\/[\w-_.]+)\/pull-requests\/(\d+)/)
20 if (parts) {
21 return {
22 platform: BitBucketServer.name,
23 repo: parts[1],
24 pullRequestNumber: parts[2],
25 }
26 }
27
28 // shape: https://bitbucket.org/proj/repo/pull-requests/1
29 if (includes(components.path, "pull-requests")) {
30 return {
31 platform: BitBucketCloud.name,
32 repo: components.path.split("/pull-requests")[0].slice(1),
33 pullRequestNumber: components.path.split("/pull-requests/")[1].split("/")[0],
34 }
35 }
36
37 // shape: http://github.com/proj/repo/pull/1
38 if (includes(components.path, "pull")) {
39 return {
40 platform: GitHub.name,
41 repo: components.path.split("/pull")[0].slice(1),
42 pullRequestNumber: components.path.split("/pull/")[1],
43 }
44 }
45
46 // shape: https://gitlab.com/GROUP[/SUBGROUP]/PROJ/merge_requests/123
47 if (includes(components.path, "merge_requests")) {
48 const regex = /\/(.+)\/merge_requests\/(\d+)/
49 const parts = components.path.match(regex)
50 if (parts) {
51 return {
52 platform: GitLab.name,
53 repo: parts[1].replace(/\/-$/, ""),
54 pullRequestNumber: parts[2],
55 }
56 }
57 }
58 }
59
60 return null
61}

Callers 5

danger-pr.tsFile · 0.90
pullRequestIDMethod · 0.90
repoSlugMethod · 0.90
repoSlugMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected