Skip to content

Commit

Permalink
Support bitbucket when gettings urls to markings
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatown committed Jun 30, 2020
1 parent 6beec8a commit cd3b380
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-apes-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@markings/cli": patch
---

Support Bitbucket when getting urls to markings
2 changes: 2 additions & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
"@markings/types": "^0.0.7",
"@types/babel__core": "^7.1.6",
"@types/babel__traverse": "^7.0.9",
"@types/normalize-path": "^3.0.0",
"@types/parse-github-url": "^1.0.0",
"chalk": "^2.4.2",
"fs-extra": "^8.1.0",
"globby": "^11.0.0",
"meow": "^5.0.0",
"normalize-path": "^3.0.0",
"p-limit": "^2.2.1",
"parse-bitbucket-url": "^0.3.0",
"parse-github-url": "^1.0.2"
},
"devDependencies": {
Expand Down
45 changes: 27 additions & 18 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @flow
import * as logger from "./logger";
import fs from "fs-extra";
import nodePath from "path";
Expand All @@ -8,7 +7,7 @@ import {
Marking,
Source,
Output,
PartialMarking
PartialMarking,
} from "@markings/types";
import mod from "module";
import globby from "globby";
Expand All @@ -17,7 +16,10 @@ import { transform, PluginObj } from "@babel/core";
import { getPackages, Package } from "@manypkg/get-packages";
// @ts-ignore
import { visitors as visitorsUtils, Visitor } from "@babel/traverse";
// @ts-ignore
import parseBitbucketUrl from "parse-bitbucket-url";
import parseGithubUrl from "parse-github-url";
import normalizePath from "normalize-path";

let parserPlugins: ParserPlugin[] = [
"asyncGenerators",
Expand All @@ -32,7 +34,7 @@ let parserPlugins: ParserPlugin[] = [
"throwExpressions",
"nullishCoalescingOperator",
"optionalChaining",
"decorators-legacy"
"decorators-legacy",
];

function getPackageFromFilename(
Expand Down Expand Up @@ -88,11 +90,11 @@ function getPackageFromFilename(
};

await Promise.all(
config.sources.map(async sourceConfig => {
config.sources.map(async (sourceConfig) => {
let result = await globby(sourceConfig.include, {
cwd,
absolute: true,
ignore: ["**/node_modules/**/*"]
ignore: ["**/node_modules/**/*"],
});

for (let filename of result) {
Expand All @@ -112,26 +114,33 @@ function getPackageFromFilename(
getUrl = (filename, line) => {
return `https://github.com/${parsed.owner}/${parsed.name}/blob/master/${filename}#L${line}`;
};
} else {
let bitbucketParsed = parseBitbucketUrl(
(pkgs.root.packageJson as any).repository
);
getUrl = (filename, line) => {
return `https://bitbucket.org/${bitbucketParsed.owner}/${bitbucketParsed.name}/src/${bitbucketParsed.branch}/${filename}#lines-${line}`;
};
}
}
let packagesByDirectory = new Map(pkgs.packages.map(x => [x.dir, x]));
let packagesByDirectory = new Map(pkgs.packages.map((x) => [x.dir, x]));
// TODO: do extraction work in worker threads
await Promise.all(
[...sourcesByFilename.entries()].map(async ([filename, sources]) => {
let visitorsArray = [...sources].map(x => req(x).source.visitor);
let visitorsArray = [...sources].map((x) => req(x).source.visitor);

let visitor: Visitor = visitorsUtils.merge(
visitorsArray,
[...sources].map(source => ({
[...sources].map((source) => ({
addMarking: (marking: PartialMarking) => {
markings.push({
location: {
line: marking.location.line,
filename,
link: getUrl(
nodePath.relative(pkgs.root.dir, filename),
normalizePath(nodePath.relative(pkgs.root.dir, filename)),
marking.location.line
)
),
},
description: marking.description,
source: source,
Expand All @@ -140,9 +149,9 @@ function getPackageFromFilename(
filename,
packagesByDirectory
).packageJson.name,
purpose: marking.purpose
purpose: marking.purpose,
});
}
},
}))
);
let contents = await fs.readFile(filename, "utf8");
Expand All @@ -156,26 +165,26 @@ function getPackageFromFilename(
parserOpts: {
plugins: parserPlugins.concat(
/\.tsx?$/.test(filename) ? "typescript" : "flow"
)
),
},
plugins: [
(): PluginObj => {
return {
visitor
visitor,
};
}
]
},
],
});
})
);
await Promise.all(
config.outputs.map(async outputConfig => {
config.outputs.map(async (outputConfig) => {
let plugin: Output = req(outputConfig.output).output;
let output = await plugin.getFile(markings);
await fs.writeFile(outputConfig.filename, output);
})
);
})().catch(err => {
})().catch((err) => {
console.log("yes");
if (err instanceof ExitError) {
process.exit(err.code);
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

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

0 comments on commit cd3b380

Please sign in to comment.