Skip to content

Commit 6e7dfbe

Browse files
authored
feat: use branch name on permalinks (#12)
1 parent 3c9352e commit 6e7dfbe

File tree

15 files changed

+130
-63
lines changed

15 files changed

+130
-63
lines changed

docs/_includes/home.md

Lines changed: 15 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/index.md

Lines changed: 30 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/reference/interfaces/GitRepo.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ An optional branch name.
3232

3333
#### Defined in
3434

35-
[types.ts:68](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L68)
35+
[types.ts:68](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L68)
3636

3737
___
3838

@@ -44,7 +44,7 @@ The file pattern / glob to match.
4444

4545
#### Defined in
4646

47-
[types.ts:58](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L58)
47+
[types.ts:58](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L58)
4848

4949
___
5050

@@ -62,7 +62,7 @@ false
6262

6363
#### Defined in
6464

65-
[types.ts:63](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L63)
65+
[types.ts:63](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L63)
6666

6767
___
6868

@@ -74,7 +74,7 @@ The remote Git repository URL.
7474

7575
#### Defined in
7676

77-
[types.ts:56](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L56)
77+
[types.ts:56](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L56)
7878

7979
___
8080

@@ -92,4 +92,4 @@ The directory where the repo should be cloned to.
9292

9393
#### Defined in
9494

95-
[types.ts:73](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L73)
95+
[types.ts:73](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L73)

docs/reference/interfaces/LocalPath.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The relative or absolute path.
2323

2424
#### Defined in
2525

26-
[types.ts:45](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L45)
26+
[types.ts:45](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L45)
2727

2828
___
2929

@@ -35,4 +35,4 @@ The file pattern / glob to match.
3535

3636
#### Defined in
3737

38-
[types.ts:47](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L47)
38+
[types.ts:47](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L47)

docs/reference/interfaces/Snippet.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The snippet content. Leading spaces are trimmed.
2727

2828
#### Defined in
2929

30-
[types.ts:20](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L20)
30+
[types.ts:20](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L20)
3131

3232
___
3333

@@ -39,7 +39,7 @@ The end line of the snippet.
3939

4040
#### Defined in
4141

42-
[types.ts:16](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L16)
42+
[types.ts:16](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L16)
4343

4444
___
4545

@@ -51,7 +51,7 @@ The name of the file, derived from `sourcePath`.
5151

5252
#### Defined in
5353

54-
[types.ts:12](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L12)
54+
[types.ts:12](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L12)
5555

5656
___
5757

@@ -63,7 +63,7 @@ The lines to be highlighted, if any.
6363

6464
#### Defined in
6565

66-
[types.ts:18](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L18)
66+
[types.ts:18](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L18)
6767

6868
___
6969

@@ -75,7 +75,7 @@ The source language. It matches the file extension.
7575

7676
#### Defined in
7777

78-
[types.ts:8](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L8)
78+
[types.ts:8](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L8)
7979

8080
___
8181

@@ -87,7 +87,7 @@ The link to the file on the remote Git repo when available.
8787

8888
#### Defined in
8989

90-
[types.ts:22](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L22)
90+
[types.ts:22](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L22)
9191

9292
___
9393

@@ -100,7 +100,7 @@ that might come from the same file extension.
100100

101101
#### Defined in
102102

103-
[types.ts:27](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L27)
103+
[types.ts:27](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L27)
104104

105105
___
106106

@@ -112,7 +112,7 @@ The file path relative to the working directory.
112112

113113
#### Defined in
114114

115-
[types.ts:10](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L10)
115+
[types.ts:10](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L10)
116116

117117
___
118118

@@ -124,4 +124,4 @@ The start line of the snippet.
124124

125125
#### Defined in
126126

127-
[types.ts:14](https://github.com/roxlabs/coldsnip/blob/f9e1b95/src/types.ts#L14)
127+
[types.ts:14](https://github.com/roxlabs/coldsnip/blob/3c9352e/src/types.ts#L14)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"docs:readme": "cp README.md ./docs/_includes/home.md",
3232
"docs:coldsnip": "./bin/run generate --source=./src --pattern=**/*.ts --format=include",
3333
"docs:typedoc": "typedoc --tsconfig tsconfig.lib.json",
34-
"docs": "npm run docs:readme & npm run docs:typedoc",
34+
"docs": "npm run docs:readme && npm run docs:typedoc",
3535
"format:imports": "organize-imports-cli tsconfig.json",
3636
"format:prettier": "prettier --write \"./**/*.{js,json,ts}\"",
3737
"format:check": "prettier --check \"./**/*.{js,json,ts}\"",

src/__tests__/createSnippet.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe("the createSnippet test suite", () => {
1616
const snippet = createSnippet({
1717
filePath: "src/index.ts",
1818
repoUrl: "https://github.com/roxlabs/coldsnip",
19-
commit: "d16f69f4eb4f46855c66420c02c586138fb38fcf",
19+
branch: "main",
2020
directory: "./",
2121
startLine: 1,
2222
endLine: 2,

src/__tests__/extractSnippets.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import extractSnippets, { findFiles } from "../extractSnippets";
33

44
describe("the extractSnippets public API test suite", () => {
55
it("should find the files from all sources", async () => {
6-
const result = await findFiles([
7-
{ path: "./", pattern: "src/__tests__/snippets/*.js" },
8-
{ url: "https://github.com/drochetti/drochetti", pattern: "*.md" },
9-
]);
6+
const result = await findFiles(
7+
[
8+
{ path: "./", pattern: "src/__tests__/snippets/*.js" },
9+
{ url: "https://github.com/drochetti/drochetti", pattern: "*.md" },
10+
],
11+
{ branch: "main" },
12+
);
1013
const paths: string[] = [];
1114
result.forEach(([files, source]) => {
1215
paths.push(...files);

src/__tests__/git.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,47 +38,47 @@ describe("the Git repo test suite", () => {
3838
it("should resolve the permalink for GitHub repos", () => {
3939
const permalink = getPermalink({
4040
repoUrl: "https://github.com/roxlabs/coldsnip",
41-
commit: "d16f69f4eb4f46855c66420c02c586138fb38fcf",
41+
branch: "main",
4242
path: "src/index.ts",
4343
startLine: 1,
4444
endLine: 3,
4545
});
4646
expect(permalink).toBe(
47-
"https://github.com/roxlabs/coldsnip/blob/d16f69f4eb4f46855c66420c02c586138fb38fcf/src/index.ts#L1-L3",
47+
"https://github.com/roxlabs/coldsnip/blob/main/src/index.ts#L1-L3",
4848
);
4949
});
5050

5151
it("should resolve the permalink for GitLab repos", () => {
5252
const permalink = getPermalink({
5353
repoUrl: "https://gitlab.com/gitlab-org/gitlab",
54-
commit: "12ecbd8580e13bd385729772102f86bcecfda04f",
54+
branch: "develop",
5555
path: "package.json",
5656
startLine: 4,
5757
endLine: 9,
5858
});
5959
expect(permalink).toBe(
60-
"https://gitlab.com/gitlab-org/gitlab/-/blob/12ecbd8580e13bd385729772102f86bcecfda04f/package.json#L4-9",
60+
"https://gitlab.com/gitlab-org/gitlab/-/blob/develop/package.json#L4-9",
6161
);
6262
});
6363

6464
it("should resolve the permalink for BitBucket repos", () => {
6565
const permalink = getPermalink({
6666
repoUrl: "https://bitbucket.org/atlassian/npm-publish",
67-
commit: "81c90f7e6b1c0859652bf6bd0dc478d99c37d6ac",
67+
branch: "staging",
6868
path: "test/test.py",
6969
startLine: 22,
7070
endLine: 27,
7171
});
7272
expect(permalink).toBe(
73-
"https://bitbucket.org/atlassian/npm-publish/src/81c90f7e6b1c0859652bf6bd0dc478d99c37d6ac/test/test.py#lines-22:27",
73+
"https://bitbucket.org/atlassian/npm-publish/src/staging/test/test.py#lines-22:27",
7474
);
7575
});
7676

7777
it("should throw an error on unsupported Git providers", () => {
7878
expect(() => {
7979
getPermalink({
8080
repoUrl: "https://unsupported.provider.com/cool/repo",
81-
commit: "main",
81+
branch: "main",
8282
path: "README.md",
8383
startLine: 1,
8484
endLine: 2,

0 commit comments

Comments
 (0)