release-cherry-pick 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -22
- package/package.json +11 -24
- package/src/git/branch-selector.js +2 -2
- package/src/git/cherry-pick.js +2 -2
- package/src/git/git-auth.js +6 -4
- package/src/git/instance.js +17 -0
- package/src/git/release-branch.js +2 -2
- package/src/git/repo-state.js +2 -2
- package/src/gitlab/client.js +2 -2
package/README.md
CHANGED
|
@@ -38,38 +38,24 @@ Given a list of task IDs (from a file, a `-b` flag, or interactive branch select
|
|
|
38
38
|
|
|
39
39
|
## Installation
|
|
40
40
|
|
|
41
|
-
Install it globally with npm or pnpm:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
npm install -g release-cherry-pick
|
|
45
|
-
# or
|
|
46
|
-
pnpm add -g release-cherry-pick
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
Or run it without installing anything:
|
|
50
|
-
|
|
51
41
|
```bash
|
|
52
|
-
|
|
53
|
-
# or
|
|
54
|
-
pnpm dlx release-cherry-pick release
|
|
42
|
+
npm install
|
|
55
43
|
```
|
|
56
44
|
|
|
57
|
-
Both expose the `release-cherry-pick` command. The tool needs to run **inside the git repository being released**, so a global install is the most practical option.
|
|
58
|
-
|
|
59
45
|
## Usage
|
|
60
46
|
|
|
61
47
|
### Run a release
|
|
62
48
|
|
|
63
49
|
```bash
|
|
64
50
|
# Interactive — pick branches from the repo
|
|
65
|
-
|
|
51
|
+
node src/index.js release
|
|
66
52
|
|
|
67
53
|
# From a branch-list file
|
|
68
|
-
|
|
54
|
+
node src/index.js release --file branches.txt
|
|
69
55
|
|
|
70
56
|
# Direct — comma-separated task IDs and/or full branch names
|
|
71
|
-
|
|
72
|
-
|
|
57
|
+
node src/index.js release --branches PB-123,PB-124
|
|
58
|
+
node src/index.js release --branches feature/PB-123-list-user,hotfix/PB-124-fix-favicon
|
|
73
59
|
```
|
|
74
60
|
|
|
75
61
|
A bare task ID is resolved to its real remote branch (same as the file input); for a full branch name, the task ID is extracted from it. Branches whose name doesn't start with a task ID are skipped with a warning.
|
|
@@ -78,10 +64,10 @@ A bare task ID is resolved to its real remote branch (same as the file input); f
|
|
|
78
64
|
|
|
79
65
|
```bash
|
|
80
66
|
# Initialize/update configuration
|
|
81
|
-
|
|
67
|
+
node src/index.js config --init
|
|
82
68
|
|
|
83
69
|
# Show current configuration
|
|
84
|
-
|
|
70
|
+
node src/index.js config --show
|
|
85
71
|
```
|
|
86
72
|
|
|
87
73
|
### Branch list file format
|
|
@@ -140,7 +126,11 @@ GitLab authentication uses a personal access token stored in `gitlab.token` (or
|
|
|
140
126
|
|
|
141
127
|
## Testing in development
|
|
142
128
|
|
|
143
|
-
There's no automated test suite yet (`npm test` is a placeholder). To validate a change:
|
|
129
|
+
There's no automated test suite yet (`npm test` is a placeholder). To validate a change, first install the git hooks once per clone (the repo has no `prepare` script on purpose, so nothing hook-related ships in the published package):
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
npm run setup # installs the Husky pre-commit hook (lint-staged → eslint --fix)
|
|
133
|
+
```
|
|
144
134
|
|
|
145
135
|
1. **Run the smoke script**, which exercises branch parsing, config defaults, status tracking, and report/doc generation:
|
|
146
136
|
```bash
|
|
@@ -166,6 +156,11 @@ There's no automated test suite yet (`npm test` is a placeholder). To validate a
|
|
|
166
156
|
npm run sandbox:config -- --fake-gitlab --answer autoCreateMR=true --answer 'defaultAssignees=["abel"]'
|
|
167
157
|
npm run sandbox:run -- --fake-gitlab -b "PB-100,PB-300" # shows the MR request body, incl. reviewer_ids/assignee_ids
|
|
168
158
|
```
|
|
159
|
+
|
|
160
|
+
To validate the **published npm package** instead of the checkout — registry tarball integrity and contents (no keys, no install lifecycle scripts, MIT, secret scan, password+mask prompts), a real `npm install` of the tarball with `--version`/`--help`/`config --show`, the mutated cherry-pick flow twice (`autoCreateMR: false` → nothing pushed; `autoCreateMR: true` → push + MR body against the fake GitLab), a secrets pass (config `0600`/`0700`, no raw token in the console output, generated report or git metadata, masked `config --show`) and a final phase against the local checkout proving simple-git ≥4.0.2 with the `GIT_CONFIG_*` token header reaching git through `createGit()`:
|
|
161
|
+
```bash
|
|
162
|
+
npm run test:package # prints a PASS/FAIL report; flags: --version <v>, --sandbox <dir>, --keep
|
|
163
|
+
```
|
|
169
164
|
4. **Exercise the real git flow against an isolated, disposable mirror** — never test branch creation, cherry-picking, or pushes directly against a real project. Clone a mirror of the target repo so pushes/branch deletes only touch your local disk:
|
|
170
165
|
```bash
|
|
171
166
|
git clone --mirror <path-or-url-to-target-repo> /tmp/rcp-test/mirror.git
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "release-cherry-pick",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "CLI tool for automating release cherry-pick and GitLab MR creation",
|
|
5
|
-
"
|
|
6
|
-
"release-cherry-pick": "src/index.js"
|
|
7
|
-
},
|
|
5
|
+
"main": "src/index.js",
|
|
8
6
|
"files": [
|
|
9
|
-
"src
|
|
7
|
+
"src"
|
|
10
8
|
],
|
|
9
|
+
"bin": {
|
|
10
|
+
"release-cherry-pick": "./src/index.js"
|
|
11
|
+
},
|
|
11
12
|
"scripts": {
|
|
12
13
|
"start": "node src/index.js",
|
|
13
14
|
"lint": "eslint .",
|
|
@@ -15,8 +16,8 @@
|
|
|
15
16
|
"sandbox:create": "bash scripts/sandbox/make-sandbox.sh",
|
|
16
17
|
"sandbox:run": "node scripts/sandbox/run-release.js",
|
|
17
18
|
"sandbox:config": "node scripts/sandbox/run-config.js",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
19
|
+
"test:package": "node scripts/sandbox/test-package.js",
|
|
20
|
+
"setup": "husky"
|
|
20
21
|
},
|
|
21
22
|
"lint-staged": {
|
|
22
23
|
"*.js": "eslint --fix"
|
|
@@ -26,24 +27,10 @@
|
|
|
26
27
|
"git",
|
|
27
28
|
"cherry-pick",
|
|
28
29
|
"gitlab",
|
|
29
|
-
"release"
|
|
30
|
-
"merge-request",
|
|
31
|
-
"automation",
|
|
32
|
-
"npx"
|
|
30
|
+
"release"
|
|
33
31
|
],
|
|
34
|
-
"author": "
|
|
32
|
+
"author": "",
|
|
35
33
|
"license": "MIT",
|
|
36
|
-
"repository": {
|
|
37
|
-
"type": "git",
|
|
38
|
-
"url": "git+https://github.com/drobinetm/release-cherry-pick.git"
|
|
39
|
-
},
|
|
40
|
-
"homepage": "https://github.com/drobinetm/release-cherry-pick#readme",
|
|
41
|
-
"bugs": {
|
|
42
|
-
"url": "https://github.com/drobinetm/release-cherry-pick/issues"
|
|
43
|
-
},
|
|
44
|
-
"publishConfig": {
|
|
45
|
-
"access": "public"
|
|
46
|
-
},
|
|
47
34
|
"type": "commonjs",
|
|
48
35
|
"engines": {
|
|
49
36
|
"node": ">=18"
|
|
@@ -55,7 +42,7 @@
|
|
|
55
42
|
"inquirer": "^8.2.7",
|
|
56
43
|
"inquirer-autocomplete-prompt": "^2.0.0",
|
|
57
44
|
"inquirer-checkbox-plus-prompt": "^1.4.2",
|
|
58
|
-
"simple-git": "^
|
|
45
|
+
"simple-git": "^4.0.2"
|
|
59
46
|
},
|
|
60
47
|
"devDependencies": {
|
|
61
48
|
"@eslint/js": "^10.0.1",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const inquirer = require('inquirer');
|
|
4
|
-
const
|
|
4
|
+
const { createGit } = require('./instance');
|
|
5
5
|
const logger = require('../utils/logger');
|
|
6
6
|
const { searchableCheckbox } = require('../utils/prompts');
|
|
7
7
|
const { defaultConfig } = require('../config/defaults');
|
|
8
8
|
|
|
9
|
-
const git =
|
|
9
|
+
const git = createGit();
|
|
10
10
|
|
|
11
11
|
// Prefixes of the branches a release can be cut from (every configured prefix except release)
|
|
12
12
|
// (falls back to the defaults when none are configured).
|
package/src/git/cherry-pick.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { createGit } = require('./instance');
|
|
4
4
|
const logger = require('../utils/logger');
|
|
5
5
|
const { GitError } = require('../utils/errors');
|
|
6
6
|
|
|
7
|
-
const git =
|
|
7
|
+
const git = createGit();
|
|
8
8
|
|
|
9
9
|
// Cherry-picks `commits` (in order) onto the current branch; when not given, the ones tagged
|
|
10
10
|
// "[taskId]" on sourceBranch that aren't on baseBranch (see getCommitsToCherryPick).
|
package/src/git/git-auth.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { createGit } = require('./instance');
|
|
4
4
|
|
|
5
5
|
function getToken(config) {
|
|
6
6
|
return (config && config.gitlab && config.gitlab.token) || process.env.GITLAB_TOKEN || '';
|
|
@@ -12,8 +12,10 @@ function getToken(config) {
|
|
|
12
12
|
// not be asked for credentials again. SSH origins already authenticate via the user's key and are
|
|
13
13
|
// left untouched. The header is injected only for this process, through env vars git itself reads
|
|
14
14
|
// (GIT_CONFIG_COUNT/KEY/VALUE, supported since Git 2.31) — it is never written to .git/config, so
|
|
15
|
-
// the token never lingers in the target repo once the CLI exits.
|
|
16
|
-
//
|
|
15
|
+
// the token never lingers in the target repo once the CLI exits. simple-git v4 strips ambient GIT_*
|
|
16
|
+
// variables from the child process, so those three are allow-listed in ./instance.js — without it
|
|
17
|
+
// this header would be dropped silently. GitLab's git-over-HTTP Basic auth validates the token
|
|
18
|
+
// itself and doesn't check the username, so any non-blank placeholder works.
|
|
17
19
|
// No-op without a token configured, or when origin isn't http(s).
|
|
18
20
|
async function configureGitCredentials(config) {
|
|
19
21
|
const token = getToken(config);
|
|
@@ -23,7 +25,7 @@ async function configureGitCredentials(config) {
|
|
|
23
25
|
|
|
24
26
|
let remoteUrl;
|
|
25
27
|
try {
|
|
26
|
-
remoteUrl = (await
|
|
28
|
+
remoteUrl = (await createGit().raw(['remote', 'get-url', 'origin'])).trim();
|
|
27
29
|
} catch {
|
|
28
30
|
return;
|
|
29
31
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { simpleGit } = require('simple-git');
|
|
4
|
+
|
|
5
|
+
// simple-git v4 strips ambient `GIT_*` variables from the environment of the git child process
|
|
6
|
+
// (they can change which program git runs), so they must be allowed explicitly. git-auth.js hands
|
|
7
|
+
// the GitLab token to git through GIT_CONFIG_COUNT/KEY/VALUE — injected per process, never written
|
|
8
|
+
// to disk — and those three would otherwise be dropped silently, sending every HTTPS fetch/pull/push
|
|
9
|
+
// back to git's interactive username/password prompt.
|
|
10
|
+
const ALLOWED_ENVIRONMENT = ['GIT_CONFIG_COUNT', 'GIT_CONFIG_KEY_0', 'GIT_CONFIG_VALUE_0'];
|
|
11
|
+
|
|
12
|
+
// Every simple-git instance in the app is created here so the allow-list above always applies.
|
|
13
|
+
function createGit() {
|
|
14
|
+
return simpleGit({ allowEnvironment: ALLOWED_ENVIRONMENT });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
module.exports = { createGit, ALLOWED_ENVIRONMENT };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const { createGit } = require('./instance');
|
|
4
4
|
const logger = require('../utils/logger');
|
|
5
5
|
const { GitError } = require('../utils/errors');
|
|
6
6
|
|
|
7
|
-
const git =
|
|
7
|
+
const git = createGit();
|
|
8
8
|
|
|
9
9
|
function buildReleaseBranchName(sourceBranch, branchPrefix = {}) {
|
|
10
10
|
let name = sourceBranch;
|
package/src/git/repo-state.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
|
-
const
|
|
5
|
+
const { createGit } = require('./instance');
|
|
6
6
|
const logger = require('../utils/logger');
|
|
7
7
|
const { GitError } = require('../utils/errors');
|
|
8
8
|
|
|
9
|
-
const git =
|
|
9
|
+
const git = createGit();
|
|
10
10
|
|
|
11
11
|
// Checks for .git/CHERRY_PICK_HEAD directly: `git rev-parse -q --verify CHERRY_PICK_HEAD` fails
|
|
12
12
|
// silently (no stderr), and simple-git only rejects when stderr has content, so it can't be used.
|
package/src/gitlab/client.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const inquirer = require('inquirer');
|
|
4
|
-
const
|
|
4
|
+
const { createGit } = require('../git/instance');
|
|
5
5
|
const logger = require('../utils/logger');
|
|
6
6
|
const { GitLabError } = require('../utils/errors');
|
|
7
7
|
const { saveConfig } = require('../config/loader');
|
|
8
8
|
const { parseRemoteUrl } = require('../git/remote-url');
|
|
9
9
|
|
|
10
|
-
const git =
|
|
10
|
+
const git = createGit();
|
|
11
11
|
const DEFAULT_HOST = 'gitlab.com';
|
|
12
12
|
|
|
13
13
|
function getToken(config) {
|