Skip to content

Commit da1ea75

Browse files
committed
Convert apache gitbox URLs to normal ones
1 parent bd35621 commit da1ea75

File tree

2 files changed

+71
-19
lines changed

2 files changed

+71
-19
lines changed

plugins/github-enricher/gatsby-node.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,14 @@ exports.onCreateNode = async (
141141

142142
// A bit ugly, we need a unique identifier in string form, and we also need the url; use a comma-separated string
143143
const id = metadata?.sourceControl
144-
const scmUrl = id?.split(",")[0]
144+
let scmUrl = id?.split(",")[0]
145+
146+
if (scmUrl?.includes("gitbox.apache.org")) {
147+
const urlState = new URL(scmUrl).search
148+
const matches = urlState?.match(/p=(.*).git;/)
149+
const projectName = matches?.length > 0 && matches[1]
150+
scmUrl = `https://github.com/apache/${projectName}`
151+
}
145152

146153
if (scmUrl) {
147154

plugins/github-enricher/gatsby-node.test.js

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ describe("the github data handler", () => {
485485
describe("where the scm-url ends with .git", () => {
486486

487487
const url = "http://phony.github.com/thing.git"
488-
const otherUrl = "http://fake.github.com/someuser/other" + projectName
489488

490489
const response = {
491490
data: {
@@ -494,18 +493,6 @@ describe("the github data handler", () => {
494493
totalCount: 16,
495494
},
496495
defaultBranchRef: { name: "unusual" },
497-
metaInfs: null,
498-
subfolderMetaInfs: null,
499-
shortenedSubfolderMetaInfs: {
500-
entries: [
501-
{ path: "runtime/src/main/resources/META-INF/beans.xml" },
502-
{
503-
path: "some-folder-name/runtime/src/main/resources/META-INF/quarkus-extension.yaml",
504-
},
505-
{ path: "runtime/src/main/resources/META-INF/services" },
506-
],
507-
},
508-
openGraphImageUrl: socialMediaPreviewUrl,
509496
},
510497
repositoryOwner: { avatarUrl: avatarUrl },
511498
},
@@ -521,13 +508,65 @@ describe("the github data handler", () => {
521508
internal,
522509
}
523510

524-
const otherMetadata = {
511+
beforeAll(async () => {
512+
queryGraphQl.mockResolvedValue(response)
513+
getContributors.mockResolvedValue({ contributors: [{ name: "someone" }], lastUpdated: Date.now() })
514+
await onPreBootstrap({ cache, actions: {} })
515+
})
516+
517+
beforeEach(async () => {
518+
// Clear the cache
519+
onPluginInit()
520+
521+
// Needed so that we do not short circuit the git path
522+
return onCreateNode({
523+
node,
524+
createContentDigest,
525+
createNodeId,
526+
actions,
527+
})
528+
})
529+
530+
afterAll(() => {
531+
jest.clearAllMocks()
532+
})
533+
534+
afterEach(() => {
535+
jest.clearAllMocks()
536+
})
537+
538+
it("fills in an issues url", async () => {
539+
expect(createNode).toHaveBeenCalledWith(
540+
expect.objectContaining({ issuesUrl: "http://phony.github.com/thing/issues" })
541+
)
542+
})
543+
544+
})
545+
546+
describe("where the scm-url is a gitbox url", () => {
547+
548+
const url = "https://gitbox.apache.org/repos/asf?p=camel-quarkus.git;a=summary"
549+
const expectedUrl = "https://github.com/apache/camel-quarkus"
550+
551+
const response = {
552+
data: {
553+
repository: {
554+
issues: {
555+
totalCount: 16,
556+
},
557+
defaultBranchRef: { name: "unusual" },
558+
},
559+
repositoryOwner: { avatarUrl: avatarUrl },
560+
},
561+
}
562+
563+
const metadata = {
525564
maven: { artifactId: "something", groupId: "grouper" },
526-
sourceControl: `${otherUrl},mavenstuff`,
565+
sourceControl: `${url},mavenstuff`,
527566
}
528567

529-
const otherNode = {
530-
metadata: otherMetadata,
568+
const node = {
569+
metadata,
531570
internal,
532571
}
533572

@@ -558,9 +597,15 @@ describe("the github data handler", () => {
558597
jest.clearAllMocks()
559598
})
560599

600+
it("adjusts the scm url", async () => {
601+
expect(createNode).toHaveBeenCalledWith(
602+
expect.objectContaining({ repository: expectedUrl })
603+
)
604+
})
605+
561606
it("fills in an issues url", async () => {
562607
expect(createNode).toHaveBeenCalledWith(
563-
expect.objectContaining({ issuesUrl: "http://phony.github.com/thing/issues" })
608+
expect.objectContaining({ issuesUrl: `${expectedUrl}/issues` })
564609
)
565610
})
566611

0 commit comments

Comments
 (0)