@psm14/semantic-release-path-filter 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +50 -0
- package/index.js +32 -6
- package/package.json +1 -1
package/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# semantic-release-path-filter
|
2
|
+
|
3
|
+
A plugin for semantic-release that filters commits based on file paths before passing them to other semantic-release plugins.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
npm install --save-dev @psm14/semantic-release-path-filter
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
This plugin wraps around other semantic-release plugins and filters the commits they receive based on file paths.
|
14
|
+
|
15
|
+
```json
|
16
|
+
{
|
17
|
+
"plugins": [
|
18
|
+
[
|
19
|
+
"@psm14/semantic-release-path-filter",
|
20
|
+
{
|
21
|
+
"path": "plugin",
|
22
|
+
"plugin": "@semantic-release/commit-analyzer"
|
23
|
+
}
|
24
|
+
],
|
25
|
+
[
|
26
|
+
"@psm14/semantic-release-path-filter",
|
27
|
+
{
|
28
|
+
"path": "plugin",
|
29
|
+
"plugin": "@semantic-release/release-notes-generator"
|
30
|
+
}
|
31
|
+
],
|
32
|
+
[
|
33
|
+
"@psm14/semantic-release-path-filter",
|
34
|
+
{
|
35
|
+
"path": "plugin",
|
36
|
+
"plugin": "@semantic-release/git"
|
37
|
+
}
|
38
|
+
],
|
39
|
+
[
|
40
|
+
"@psm14/semantic-release-path-filter",
|
41
|
+
{
|
42
|
+
"path": "plugin",
|
43
|
+
"plugin": "@semantic-release/github"
|
44
|
+
}
|
45
|
+
]
|
46
|
+
]
|
47
|
+
}
|
48
|
+
```
|
49
|
+
|
50
|
+
The `plugin` option may be a string or an array consisting of the name and a configuration object.
|
package/index.js
CHANGED
@@ -1,21 +1,38 @@
|
|
1
1
|
import { execSync } from "child_process";
|
2
2
|
|
3
|
-
function filterCommits(commits, path) {
|
3
|
+
function filterCommits({ commits, logger }, path) {
|
4
4
|
return commits.filter((commit) => {
|
5
5
|
const changedFiles = getChangedFiles(commit.hash);
|
6
|
-
|
6
|
+
const isRelevant = changedFiles.some((file) => file.startsWith(path));
|
7
|
+
if (!isRelevant) {
|
8
|
+
logger.info(
|
9
|
+
`Filtered out commit ${commit.hash.slice(
|
10
|
+
0,
|
11
|
+
7
|
12
|
+
)} as it doesn't affect '${path}'`
|
13
|
+
);
|
14
|
+
}
|
15
|
+
return isRelevant;
|
7
16
|
});
|
8
17
|
}
|
9
18
|
|
19
|
+
const CHANGED_FILES_MEMO = new Map();
|
20
|
+
|
10
21
|
function getChangedFiles(commitHash) {
|
22
|
+
if (CHANGED_FILES_MEMO.has(commitHash)) {
|
23
|
+
return CHANGED_FILES_MEMO.get(commitHash);
|
24
|
+
}
|
25
|
+
|
11
26
|
try {
|
12
27
|
const result = execSync(
|
13
28
|
`git diff-tree --no-commit-id --name-only -r ${commitHash}`,
|
14
29
|
{ encoding: "utf-8" }
|
15
30
|
);
|
16
|
-
|
31
|
+
const changedFiles = result.trim().split("\n");
|
32
|
+
CHANGED_FILES_MEMO.set(commitHash, changedFiles);
|
33
|
+
return changedFiles;
|
17
34
|
} catch (error) {
|
18
|
-
|
35
|
+
logger.error(
|
19
36
|
`Error getting changed files for commit ${commitHash}:`,
|
20
37
|
error
|
21
38
|
);
|
@@ -37,13 +54,22 @@ function makePlugin(name) {
|
|
37
54
|
return;
|
38
55
|
}
|
39
56
|
|
57
|
+
const scopedLogger = context.logger.scope(
|
58
|
+
...context.logger.scopeName,
|
59
|
+
originalPluginName
|
60
|
+
);
|
40
61
|
const filteredContext =
|
41
62
|
"commits" in context
|
42
63
|
? {
|
43
64
|
...context,
|
44
|
-
commits: filterCommits(context
|
65
|
+
commits: filterCommits(context, path),
|
66
|
+
logger: scopedLogger,
|
45
67
|
}
|
46
|
-
:
|
68
|
+
: {
|
69
|
+
...context,
|
70
|
+
logger: scopedLogger,
|
71
|
+
};
|
72
|
+
|
47
73
|
return pluginModule[name](originalPluginConfig, filteredContext);
|
48
74
|
};
|
49
75
|
}
|