Skip to content

Commit

Permalink
Merge pull request #114 from pulsar-edit/fix-bad-gh-urls
Browse files Browse the repository at this point in the history
Resolve incorrect "Repo" URLs being provided
  • Loading branch information
confused-Techie authored Jul 21, 2023
2 parents b5e6f30 + abc63db commit fecec30
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"markdown-it-highlightjs": "^4.0.1",
"markdown-it-task-checkbox": "^1.0.6",
"minify": "^9.2.0",
"parse-github-url": "^1.0.2",
"superagent": "^8.0.1",
"tailwindcss": "^3.2.4"
},
Expand Down
38 changes: 26 additions & 12 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

const MarkdownIt = require("markdown-it");
const url = require('url');
const ghurl = require("parse-github-url");
let md = new MarkdownIt({
html: true
}).use(require("markdown-it-highlightjs"), {
Expand Down Expand Up @@ -277,21 +278,34 @@ function findRepoField(obj) {
(typeof obj.metadata.repository === "object" ? obj.metadata.repository.url : "" ));
/**
* For Information: ./docs/repository-urls.md
* Now we are using `https://github.com/jonschlinkert/parse-github-url`
* So there's no need to manually maintain this full code, but instead of complete deletion
* it will be mothballed by being commented out until a later time.
*/

if (reg.repoLink.standard.test(repo)) {
// Standard repo definition, it's a valid link. Return
return repo;
} else if (reg.repoLink.protocol.test(repo)) {
// Git Protocol Defined. Create normalized link.
let constru = repo.match(reg.repoLink.protocol);
return `https://github.com/${constru[1]}/${constru[2].replace(".git","")}`;
} else if (reg.repoLink.githubAssumedShorthand.test(repo)) {
return `https://github.com/${repo.match(reg.repoLink.githubAssumedShorthand)[0]}`;
} else if (reg.repoLink.githubShorthand.test(repo)) {
return `https://github.com/${repo.match(reg.repoLink.githubShorthand)[1]}`;

// if (reg.repoLink.standard.test(repo)) {
// // Standard repo definition, it's a valid link. Return
// return repo;
// } else if (reg.repoLink.protocol.test(repo)) {
// // Git Protocol Defined. Create normalized link.
// let constru = repo.match(reg.repoLink.protocol);
// return `https://github.com/${constru[1]}/${constru[2].replace(".git","")}`;
// } else if (reg.repoLink.githubAssumedShorthand.test(repo)) {
// return `https://github.com/${repo.match(reg.repoLink.githubAssumedShorthand)[0]}`;
// } else if (reg.repoLink.githubShorthand.test(repo)) {
// return `https://github.com/${repo.match(reg.repoLink.githubShorthand)[1]}`;
// } else {
// // We couldn't determine what to do here. Just return.
// return repo;
// }

let repoObj = ghurl(repo);

if (repoObj.hasOwnProperty("repo")) {
return `https://github.com/${repoObj.repo}`;
} else {
// We couldn't determine what to do here. Just return.
// Unable to parse URL, return as is
return repo;
}

Expand Down

0 comments on commit fecec30

Please sign in to comment.