@lbdudc/linea-cli 0.3.1 → 0.3.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 +61 -21
- package/dist/{chunk-byt4gzdm.js → chunk-7fb64a6k.js} +204 -18
- package/dist/{chunk-tg9jv9kp.js → chunk-9fk7bmpf.js} +2 -2
- package/dist/{chunk-pb6gdhgt.js → chunk-hze8x0qk.js} +49 -70
- package/dist/{chunk-xxy3p5cy.js → chunk-svnnnkkc.js} +2 -2
- package/dist/{chunk-e0n1mfcb.js → chunk-t9dajtj7.js} +1 -1
- package/dist/{chunk-v0bv81ad.js → chunk-wynchwk9.js} +3 -3
- package/dist/{chunk-r3nqk2zv.js → chunk-wzf7ny2m.js} +482 -157
- package/dist/index.js +4 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ From a checkout of [lbdudc/linea](https://github.com/lbdudc/linea): `npm install
|
|
|
35
35
|
| **configure products** | `product new shop --features A,B` → `product show shop` → `open shop:datamodel` → `check shop` → `generate shop` |
|
|
36
36
|
| **write modules or metamodels** | `module new auth` → edit → `check auth` → `module publish auth --bump minor --to my-group`; to change one that exists: `get github:acme/auth` |
|
|
37
37
|
| **use LINEA from CI** | `linea --json check` (exit code 1 when something does not fit) |
|
|
38
|
-
| **start on your laptop** | `spl new gis
|
|
38
|
+
| **start on your laptop** | `mode offline` → `spl new gis` → `module list --remote` → `spl add github:acme/auth` → (later) `mode server`, `login`, `push` uploads it to LINEA |
|
|
39
39
|
|
|
40
40
|
## Where you are decides what is meant
|
|
41
41
|
|
|
@@ -58,17 +58,50 @@ for. `linea config workspace <folder>` sets the default one; standing in a works
|
|
|
58
58
|
- **`push`** sends things up: it checks, commits, pushes a branch and opens the merge/pull request. If the SPL was made here and LINEA
|
|
59
59
|
does not have it yet, `push` uploads it first.
|
|
60
60
|
|
|
61
|
-
And what you create goes where you are working: signed in, `spl new` makes the SPL **on LINEA and brings it to your
|
|
62
|
-
`product new`, inside an SPL that is on LINEA, makes the product there and brings it into the SPL's folder.
|
|
63
|
-
here (`push`
|
|
64
|
-
|
|
65
|
-
There is no mode to think about: a command acts on the folder you are in, and goes to LINEA only when it has to (`get`, `push`, `spl list`,
|
|
66
|
-
`spl new`, `product new`, `generate --remote`, and the few commands that only exist there: `product logs`, `product conflicts`,
|
|
67
|
-
`reconcile`, `namespaces`). `--local` means "do not talk to the server" for one command.
|
|
61
|
+
And what you create goes where you are working: in **server mode**, signed in, `spl new` makes the SPL **on LINEA and brings it to your
|
|
62
|
+
folder**, and `product new`, inside an SPL that is on LINEA, makes the product there and brings it into the SPL's folder. **Offline**
|
|
63
|
+
it is made only here (`push` uploads it later). `spl list` shows both sides in one list: *here + LINEA*, *here only*, *LINEA only*.
|
|
68
64
|
|
|
69
65
|
Changing something that LINEA has is always the same loop: `get` it, change it in your folder, `push` it. That is why there is no
|
|
70
66
|
`rename`, `delete` or `update` of things on the server from here: do those in the web interface, and `get` the result.
|
|
71
67
|
|
|
68
|
+
## Two modes: server and offline
|
|
69
|
+
|
|
70
|
+
linea is always in one of two modes, and it tells you which wherever you look:
|
|
71
|
+
|
|
72
|
+
| Mode | What it means | Shown as |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| **server** | works with the LINEA server and the remotes it has: your SPLs there, `push`, pipelines, `spl new` on LINEA | `● server linea.example.org · GitLab as ana` |
|
|
75
|
+
| **offline** | this machine only: SPLs in folders, `generate` here, nothing asks the server | `○ offline · this machine only` |
|
|
76
|
+
|
|
77
|
+
`◐ server … · not signed in` means the server is wanted but there is no sign-in (`login`), and `◐ … session expired` that it has to be
|
|
78
|
+
renewed (`login` again). That line is the status bar of the window, the top of the welcome, and what a command that talks to the server
|
|
79
|
+
prints on stderr before it runs (never with `--json`, and never on stdout, so scripts read the same output as before).
|
|
80
|
+
|
|
81
|
+
- `mode` shows it; `mode server` / `mode offline` choose it (kept between runs). `login` makes it `server` and says so.
|
|
82
|
+
- `--offline` makes one command offline (`--local` still works, and is the same). `LINEA_MODE=server|offline` does it for one run.
|
|
83
|
+
- **linea never switches by itself.** A command that needs the server says so offline (`✗ product logs needs the LINEA server, and linea
|
|
84
|
+
is offline … Switch: mode server`); in server mode with no sign-in, `spl list`, `spl new` and `product new` refuse and say `login`
|
|
85
|
+
(or `--offline`) instead of quietly doing the local thing. If the server cannot be reached, it says so and suggests `mode offline`.
|
|
86
|
+
- Commands about folders (`check`, `fm`, `generate`, `open`, `product list`…) work in both modes.
|
|
87
|
+
|
|
88
|
+
(The word *local* is the **server's** own git host, shown as **LINEA git**; the CLI's no-server state is *offline*.)
|
|
89
|
+
|
|
90
|
+
## One server, several remotes
|
|
91
|
+
|
|
92
|
+
A LINEA server connects to **remotes** (git hosts): its own git (**LINEA git**, `local`), **GitLab** and **GitHub**, any of them on. You
|
|
93
|
+
point linea at one server (`server <url>`; `server` shows it and the remotes it has; changing it signs you out, so it asks for `--yes`).
|
|
94
|
+
|
|
95
|
+
| Command | What it does |
|
|
96
|
+
|---|---|
|
|
97
|
+
| `remote` | the remotes of the server, the one you work on (`●`), your account on each, and how to sign in with each |
|
|
98
|
+
| `remote use <name>` | work on another remote. The server keeps the choice for your account, so **the web page follows** (and the other way round: `whoami` asks again) |
|
|
99
|
+
| `remote link <name> [--device]` | add your account on another remote (browser, or a code on a machine with no browser). LINEA git accounts cannot be linked: they sign in with a password |
|
|
100
|
+
| `remote unlink <name>` | forget an account (not the one you sign in with) |
|
|
101
|
+
| `whoami` | mode, server, who you are, the remote you work on, the accounts you have, and where git access comes from |
|
|
102
|
+
|
|
103
|
+
Lists, new SPLs and products, and the git access (`get`, `push`) are always of the remote you work on.
|
|
104
|
+
|
|
72
105
|
## Configuration
|
|
73
106
|
|
|
74
107
|
| | Default | Purpose |
|
|
@@ -89,15 +122,22 @@ Bun reads a `.env` in the folder you start from; `bun --no-env-file` ignores it.
|
|
|
89
122
|
|
|
90
123
|
## Signing in
|
|
91
124
|
|
|
92
|
-
`
|
|
93
|
-
|
|
94
|
-
|
|
125
|
+
`login [remote]` signs in to the server **through** one of its remotes (the primary one when you do not say; `remote` lists them):
|
|
126
|
+
|
|
127
|
+
| How | Command | For |
|
|
128
|
+
|---|---|---|
|
|
129
|
+
| browser | `login gitlab` (or `github`) | the usual one: opens your browser on the remote (loopback `http://127.0.0.1:53682/callback`; `LINEA_OAUTH_PORT` changes the port, and the OAuth application has to accept it) |
|
|
130
|
+
| code | `login gitlab --device` | a machine with no browser (SSH, a container): it shows an address and a code, you approve on another screen |
|
|
131
|
+
| token | `login gitlab --token <token or file>` | a personal access token of the remote (GitLab: `api`; GitHub: `repo`), **for someone who has signed in to LINEA once before** (a token never makes a new account). Also kept as your git access for that remote |
|
|
132
|
+
| password | `login local --username ana --password <password or file>` | LINEA git accounts (`LINEA_PASSWORD` works too); `login local --token <git token>` uses the account's git token |
|
|
133
|
+
|
|
134
|
+
When it comes back the CLI has **both** things it needs: a session on the LINEA server, and your own access to the git host, which the
|
|
135
|
+
server hands over once (`/api/users/git-credentials`). `--device` and the server-side `--token` need a server that has them (`remote`
|
|
136
|
+
lists `code` and `token` per remote); an older one answers with a clear message, and `login --token` still gives git access there.
|
|
95
137
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
never printed, and it is kept over whatever the server says later. Git access belongs to the server it came from: switching servers
|
|
100
|
-
(`config server …`) leaves the other's behind, and `doctor` says where the access in use comes from.
|
|
138
|
+
A **personal token** is kept **per remote** and over whatever the server says later, so `remote use` back to that remote gives it again.
|
|
139
|
+
It is never printed. Git access belongs to the server it came from: `server <other-url>` leaves the other's behind, and `doctor` says
|
|
140
|
+
where the access in use comes from.
|
|
101
141
|
|
|
102
142
|
The access is also what `git` uses: a clone is configured with `linea` as its credential helper for that host, so a plain `git push`
|
|
103
143
|
or `git pull` inside it works too, and no token is written into any repository.
|
|
@@ -127,20 +167,20 @@ Anything marked `local` or `cloud` works only there.
|
|
|
127
167
|
| `open [what] [--editor name] [--print]` | the SPL (as a VS Code workspace with its modules), a product, `shop:datamodel`, `fm`, a module, a path |
|
|
128
168
|
| `open --web`, `open --repo` | the same thing in the LINEA web interface, or on the GitLab/GitHub page |
|
|
129
169
|
|
|
130
|
-
Some commands were folded into others and no longer appear in `help
|
|
170
|
+
Some commands were folded into others and no longer appear in `help`: `clone`, `pull` and `link` are used by `get` and `push` (they are not commands of their own); `web` and `repo` are `open --web` and `--repo`; `profile` is `remote`; `spl modules` is in `spl show`; `product models` and `product conflicts` are in `product show`; `fm edit` is `open fm`; `module clone` is `get gitlab:group/project`. (`fm convert` no longer exists.)
|
|
131
171
|
|
|
132
172
|
### SPLs, the feature model and products
|
|
133
173
|
|
|
134
174
|
| | |
|
|
135
175
|
|---|---|
|
|
136
176
|
| `spl list`, `spl show [spl]` | your SPLs, here and on LINEA in one list, coloured by where each is (green: here and on LINEA, yellow: only here, cyan: only on LINEA); what one is made of (for one of modules: the modules it names and what they bring in), its products, and whether LINEA has it |
|
|
137
|
-
| `spl new <name> [--modules gitlab:g/m,…] [--plain] [--
|
|
177
|
+
| `spl new <name> [--modules gitlab:g/m,…] [--plain] [--offline]` | made of modules by default; `--plain` is the classic kind (a feature model and nothing else: the data model and the sensors are metamodels of modules). In server mode, signed in, it is made on LINEA (on the remote you work on) and comes to your folder; offline (or `--offline`) it is made here |
|
|
138
178
|
| `spl add <module> [range]`, `spl remove <module>` | choose the modules; what they need comes with them |
|
|
139
179
|
| `spl update [module]` | take the newest versions the ranges allow and pin them in `linea.lock.json` |
|
|
140
180
|
| `spl delete <spl> --yes` | delete it from this machine (irreversible, products included); LINEA keeps its own copy |
|
|
141
181
|
| `check [product\|module\|metamodel]` | an SPL (its modules fit), a product (its models and features fit) or a package, by what you name or where you are |
|
|
142
182
|
| `fm show\|convert\|analyze\|metric` | the feature model (to change it: `open fm`) |
|
|
143
|
-
| `product new <name> [--features A,B] [--from spec.json] [--
|
|
183
|
+
| `product new <name> [--features A,B] [--from spec.json] [--offline]` | a product; in an SPL that is on LINEA it is made there and comes into the folder. For an SPL of modules it starts with a model of each metamodel it needs |
|
|
144
184
|
| `product list\|show\|rename\|delete` | the products of the SPL you are in (here, on this machine); `show` has its features, its models and what is missing, and the merge requests LINEA knows of |
|
|
145
185
|
| `product features <product> [--add A,B] [--remove C]` | the features a product selects |
|
|
146
186
|
| `generate [product] [--preview [dir]] [--zip [file]] [--remote [--bump patch\|minor\|major] [--no-wait]]` | derive it here, into the product's folder (then `push`); `--preview` and `--zip` leave it alone; `--remote` has LINEA derive it, open its merge requests and follow its pipeline (`--no-wait` does not) |
|
|
@@ -170,7 +210,7 @@ Some commands were folded into others and no longer appear in `help`, but still
|
|
|
170
210
|
|
|
171
211
|
## Scripts and CI
|
|
172
212
|
|
|
173
|
-
- `--json` prints data instead of text (`status`, `check`, `module list`, `doctor`…); `--
|
|
213
|
+
- `--json` prints data instead of text (`status`, `check`, `module list`, `doctor`…); `--offline` says no server for one command (`LINEA_MODE=offline` for the whole run). The line that says where a command of the server worked goes to stderr.
|
|
174
214
|
- The exit code is `0` when it worked, `1` when it did not or a check found problems, `2` when the command was used wrong.
|
|
175
215
|
- Normal output goes to stdout, errors and notes to stderr.
|
|
176
216
|
|
|
@@ -250,4 +290,4 @@ bun run build # dist/index.js, what `linea` runs
|
|
|
250
290
|
|
|
251
291
|
The tests that touch git run the real `git`; the LOCAL ones stub `fetch` to throw, so a stray network call fails them.
|
|
252
292
|
`@lbdudc/linea-git/testing` serves an in-memory GitLab and GitHub that also speak git over HTTP, which is what the dev stack
|
|
253
|
-
(`
|
|
293
|
+
(`apps/server/dev`) uses, so `get` and `push` can be tried against it without a real host.
|
|
@@ -2826,6 +2826,15 @@ class PackageVersionInvalidError extends Error {
|
|
|
2826
2826
|
this.name = "PackageVersionInvalidError";
|
|
2827
2827
|
}
|
|
2828
2828
|
}
|
|
2829
|
+
|
|
2830
|
+
class GitDeviceFlowError extends GitAuthError {
|
|
2831
|
+
reason;
|
|
2832
|
+
constructor(reason, message = reason) {
|
|
2833
|
+
super(message);
|
|
2834
|
+
this.name = "GitDeviceFlowError";
|
|
2835
|
+
this.reason = reason;
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2829
2838
|
// ../git/dist/config.js
|
|
2830
2839
|
var list = (value) => (value ?? "").split(",").map((entry) => entry.trim()).filter(Boolean);
|
|
2831
2840
|
var gitConfigFromEnv = (env = process.env) => {
|
|
@@ -2860,6 +2869,16 @@ var gitConfigFromEnv = (env = process.env) => {
|
|
|
2860
2869
|
// ../git/dist/github/provider.js
|
|
2861
2870
|
import crypto2 from "crypto";
|
|
2862
2871
|
|
|
2872
|
+
// ../git/dist/access.js
|
|
2873
|
+
var ACCESS = {
|
|
2874
|
+
MINIMAL: 5,
|
|
2875
|
+
GUEST: 10,
|
|
2876
|
+
REPORTER: 20,
|
|
2877
|
+
DEVELOPER: 30,
|
|
2878
|
+
MAINTAINER: 40,
|
|
2879
|
+
OWNER: 50
|
|
2880
|
+
};
|
|
2881
|
+
|
|
2863
2882
|
// ../git/dist/templates.js
|
|
2864
2883
|
var LAYOUTS = {
|
|
2865
2884
|
gitlab: {
|
|
@@ -3031,6 +3050,59 @@ class GitHubClient {
|
|
|
3031
3050
|
}
|
|
3032
3051
|
}
|
|
3033
3052
|
|
|
3053
|
+
// ../git/dist/device.js
|
|
3054
|
+
var DEVICE_GRANT = "urn:ietf:params:oauth:grant-type:device_code";
|
|
3055
|
+
async function postForm(url, params) {
|
|
3056
|
+
const body = new URLSearchParams;
|
|
3057
|
+
for (const [key, value] of Object.entries(params))
|
|
3058
|
+
if (value !== undefined && value !== "")
|
|
3059
|
+
body.set(key, value);
|
|
3060
|
+
const response = await fetch(url, {
|
|
3061
|
+
method: "POST",
|
|
3062
|
+
headers: { Accept: "application/json", "Content-Type": "application/x-www-form-urlencoded", "User-Agent": "linea" },
|
|
3063
|
+
body,
|
|
3064
|
+
signal: AbortSignal.timeout(30000)
|
|
3065
|
+
});
|
|
3066
|
+
const data = await response.json().catch(() => ({}));
|
|
3067
|
+
return { status: response.status, data };
|
|
3068
|
+
}
|
|
3069
|
+
async function startDevice(url, params) {
|
|
3070
|
+
const { status, data } = await postForm(url, params);
|
|
3071
|
+
if (data.error === "device_flow_disabled")
|
|
3072
|
+
throw new GitDeviceFlowError("device_flow_disabled", data.error_description ?? "device flow is off for this OAuth app");
|
|
3073
|
+
if (status === 404 || status === 405)
|
|
3074
|
+
throw new GitDeviceFlowError("unsupported", "this host does not offer device sign-in");
|
|
3075
|
+
if (status >= 400 || data.error || !data.device_code)
|
|
3076
|
+
throw new GitError(data.error_description ?? data.error ?? `device authorization failed (${status})`, status);
|
|
3077
|
+
return {
|
|
3078
|
+
deviceCode: data.device_code,
|
|
3079
|
+
userCode: data.user_code,
|
|
3080
|
+
verificationUri: data.verification_uri ?? data.verification_url,
|
|
3081
|
+
verificationUriComplete: data.verification_uri_complete,
|
|
3082
|
+
expiresIn: Number(data.expires_in ?? 900),
|
|
3083
|
+
interval: Number(data.interval ?? 5)
|
|
3084
|
+
};
|
|
3085
|
+
}
|
|
3086
|
+
async function pollDevice(url, params, interval = 5) {
|
|
3087
|
+
const { status, data } = await postForm(url, { grant_type: DEVICE_GRANT, ...params });
|
|
3088
|
+
if (data.access_token)
|
|
3089
|
+
return { status: "done", tokens: { accessToken: data.access_token, refreshToken: data.refresh_token ?? null } };
|
|
3090
|
+
switch (data.error) {
|
|
3091
|
+
case "authorization_pending":
|
|
3092
|
+
return { status: "pending", interval };
|
|
3093
|
+
case "slow_down":
|
|
3094
|
+
return { status: "pending", interval: Number(data.interval ?? interval + 5) };
|
|
3095
|
+
case "expired_token":
|
|
3096
|
+
throw new GitDeviceFlowError("expired_token", "the code expired");
|
|
3097
|
+
case "access_denied":
|
|
3098
|
+
throw new GitDeviceFlowError("access_denied", "sign-in was refused");
|
|
3099
|
+
case "device_flow_disabled":
|
|
3100
|
+
throw new GitDeviceFlowError("device_flow_disabled", data.error_description);
|
|
3101
|
+
default:
|
|
3102
|
+
throw new GitError(data.error_description ?? data.error ?? `device sign-in failed (${status})`, status);
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
|
|
3034
3106
|
// ../git/dist/github/config.js
|
|
3035
3107
|
var trimmed = (url) => url.replace(/\/+$/, "");
|
|
3036
3108
|
var githubWebUrl = (config = {}) => trimmed(config.webUrl ?? "https://github.com");
|
|
@@ -3165,6 +3237,12 @@ class GitHubProvider {
|
|
|
3165
3237
|
throw new GitAuthError(data.error_description ?? data.error ?? "unauthorized");
|
|
3166
3238
|
return { accessToken: data.access_token, refreshToken: data.refresh_token ?? null };
|
|
3167
3239
|
}
|
|
3240
|
+
startDeviceAuthorization({ scope = GITHUB_SCOPE } = {}) {
|
|
3241
|
+
return startDevice(`${githubWebUrl(this.config)}/login/device/code`, { client_id: this.config.clientId, scope });
|
|
3242
|
+
}
|
|
3243
|
+
pollDeviceAuthorization({ deviceCode, interval }) {
|
|
3244
|
+
return pollDevice(`${githubWebUrl(this.config)}/login/oauth/access_token`, { device_code: deviceCode, client_id: this.config.clientId, client_secret: this.config.clientSecret }, interval);
|
|
3245
|
+
}
|
|
3168
3246
|
exchangeCode({ code, redirectUri }) {
|
|
3169
3247
|
return this.tokenRequest({ code, redirect_uri: redirectUri });
|
|
3170
3248
|
}
|
|
@@ -3306,6 +3384,29 @@ class GitHubProvider {
|
|
|
3306
3384
|
async getAccessLevel({ token, id }) {
|
|
3307
3385
|
return accessLevelOf((await this.repoJson(token, id)).permissions);
|
|
3308
3386
|
}
|
|
3387
|
+
async listAccess({ token, id }) {
|
|
3388
|
+
const repo = await this.repoJson(token, id);
|
|
3389
|
+
const path = `/repos/${repo.full_name}/collaborators`;
|
|
3390
|
+
const [everybody, direct] = await Promise.all([
|
|
3391
|
+
this.client.paginate({ token, path: `${path}?affiliation=all` }),
|
|
3392
|
+
this.client.paginate({ token, path: `${path}?affiliation=direct` })
|
|
3393
|
+
]);
|
|
3394
|
+
const own = new Set(direct.map((member) => member.login));
|
|
3395
|
+
return everybody.map((member) => ({ username: member.login, accessLevel: LEVELS[member.role_name] ?? accessLevelOf(member.permissions), source: own.has(member.login) ? "direct" : "inherited" })).filter((entry) => entry.accessLevel >= ACCESS.REPORTER);
|
|
3396
|
+
}
|
|
3397
|
+
async setAccess({ token, id, username, accessLevel }) {
|
|
3398
|
+
const repo = await this.repoJson(token, id);
|
|
3399
|
+
const permission = accessLevel >= ACCESS.OWNER ? "admin" : accessLevel >= ACCESS.MAINTAINER ? "maintain" : accessLevel >= ACCESS.DEVELOPER ? "push" : "pull";
|
|
3400
|
+
await this.json(token, `/repos/${repo.full_name}/collaborators/${encodeURIComponent(username)}`, { method: "PUT", body: { permission } });
|
|
3401
|
+
}
|
|
3402
|
+
async removeAccess({ token, id, username }) {
|
|
3403
|
+
const repo = await this.repoJson(token, id);
|
|
3404
|
+
await this.json(token, `/repos/${repo.full_name}/collaborators/${encodeURIComponent(username)}`, { method: "DELETE" });
|
|
3405
|
+
}
|
|
3406
|
+
async searchUsers({ token, query }) {
|
|
3407
|
+
const found = await this.json(token, `/search/users?q=${encodeURIComponent(query)}&per_page=10`);
|
|
3408
|
+
return (found.items ?? []).map((user) => ({ username: user.login, name: user.login, avatarUrl: user.avatar_url ?? null }));
|
|
3409
|
+
}
|
|
3309
3410
|
async toFile(token, repo, json) {
|
|
3310
3411
|
let content = String(json.content ?? "").replace(/\n/g, "");
|
|
3311
3412
|
if (json.encoding === "none" || content === "" && json.size > 0) {
|
|
@@ -3658,6 +3759,11 @@ class GitHubProvider {
|
|
|
3658
3759
|
const repo = await this.repoJson(token, id);
|
|
3659
3760
|
return (await this.client.paginate({ token, path: `/repos/${repo.full_name}/issues/${number}/comments` })).map((json) => this.toComment(json));
|
|
3660
3761
|
}
|
|
3762
|
+
async listIssueLabelEvents({ token, id, number }) {
|
|
3763
|
+
const repo = await this.repoJson(token, id);
|
|
3764
|
+
const events = await this.client.paginate({ token, path: `/repos/${repo.full_name}/issues/${number}/events` });
|
|
3765
|
+
return events.filter((event) => (event.event === "labeled" || event.event === "unlabeled") && event.label?.name).map((event) => ({ label: event.label.name, action: event.event === "unlabeled" ? "removed" : "added", author: event.actor?.login, createdAt: event.created_at })).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
3766
|
+
}
|
|
3661
3767
|
async addIssueComment({ token, id, number, body }) {
|
|
3662
3768
|
const repo = await this.repoJson(token, id);
|
|
3663
3769
|
return this.toComment(await this.json(token, `/repos/${repo.full_name}/issues/${number}/comments`, { method: "POST", body: { body } }));
|
|
@@ -4825,8 +4931,10 @@ var appFetch = async ({ url, token, method, path, body, json = true, api = "api/
|
|
|
4825
4931
|
}
|
|
4826
4932
|
if (!json)
|
|
4827
4933
|
return res;
|
|
4828
|
-
if (res.ok)
|
|
4829
|
-
|
|
4934
|
+
if (res.ok) {
|
|
4935
|
+
const raw = await res.text();
|
|
4936
|
+
return raw ? JSON.parse(raw) : null;
|
|
4937
|
+
}
|
|
4830
4938
|
let detail = {};
|
|
4831
4939
|
try {
|
|
4832
4940
|
const raw = await res.text();
|
|
@@ -5150,6 +5258,12 @@ class GitLabProvider {
|
|
|
5150
5258
|
async exchangeCode({ code, redirectUri }) {
|
|
5151
5259
|
return toTokens(await this.session.requestAccessToken(code, this.config.clientId, this.config.clientSecret, redirectUri));
|
|
5152
5260
|
}
|
|
5261
|
+
startDeviceAuthorization({ scope = "api" } = {}) {
|
|
5262
|
+
return startDevice(`${this.config.url}/oauth/authorize_device`, { client_id: this.config.clientId, scope });
|
|
5263
|
+
}
|
|
5264
|
+
pollDeviceAuthorization({ deviceCode, interval }) {
|
|
5265
|
+
return pollDevice(`${this.config.url}/oauth/token`, { device_code: deviceCode, client_id: this.config.clientId, client_secret: this.config.clientSecret }, interval);
|
|
5266
|
+
}
|
|
5153
5267
|
async refreshToken({ refreshToken }) {
|
|
5154
5268
|
return toTokens(await this.session.refreshAccessToken(refreshToken ?? "", this.config.clientId, this.config.clientSecret, this.config.redirectUri ?? ""));
|
|
5155
5269
|
}
|
|
@@ -5242,6 +5356,40 @@ class GitLabProvider {
|
|
|
5242
5356
|
async getAccessLevel({ token, id, username }) {
|
|
5243
5357
|
return (await this.getMembers({ token, id })).find((member) => member.username === username)?.accessLevel ?? 0;
|
|
5244
5358
|
}
|
|
5359
|
+
async listAccess({ token, id }) {
|
|
5360
|
+
const project = await this.client.getProject(token, id);
|
|
5361
|
+
const [everybody, direct] = await Promise.all([
|
|
5362
|
+
this.client.listPaged(token, `projects/${project.id}/members/all`),
|
|
5363
|
+
this.client.listPaged(token, `projects/${project.id}/members`)
|
|
5364
|
+
]);
|
|
5365
|
+
const own = new Map(direct.map((member) => [member.username, member.access_level]));
|
|
5366
|
+
return everybody.filter((member) => member.access_level >= ACCESS.REPORTER).map((member) => ({ username: member.username, accessLevel: member.access_level, source: own.get(member.username) === member.access_level ? "direct" : "inherited" }));
|
|
5367
|
+
}
|
|
5368
|
+
async setAccess({ token, id, username, accessLevel }) {
|
|
5369
|
+
const project = await this.client.getProject(token, id);
|
|
5370
|
+
const user = await this.userByName(token, username);
|
|
5371
|
+
const direct = await this.client.listPaged(token, `projects/${project.id}/members`);
|
|
5372
|
+
const exists = direct.some((member) => member.id === user.id);
|
|
5373
|
+
await this.client.send(token, exists ? "PUT" : "POST", `projects/${project.id}/members${exists ? `/${user.id}` : ""}`, exists ? { access_level: accessLevel } : { user_id: user.id, access_level: accessLevel });
|
|
5374
|
+
}
|
|
5375
|
+
async removeAccess({ token, id, username }) {
|
|
5376
|
+
const project = await this.client.getProject(token, id);
|
|
5377
|
+
const user = await this.userByName(token, username);
|
|
5378
|
+
await this.client.send(token, "DELETE", `projects/${project.id}/members/${user.id}`).catch((error) => {
|
|
5379
|
+
if (error.status !== 404)
|
|
5380
|
+
throw error;
|
|
5381
|
+
});
|
|
5382
|
+
}
|
|
5383
|
+
async searchUsers({ token, query }) {
|
|
5384
|
+
const found = await this.client.get(token, `users?search=${encodeURIComponent(query)}&per_page=10&active=true`);
|
|
5385
|
+
return found.map((user) => ({ username: user.username, name: user.name ?? user.username, avatarUrl: user.avatar_url ?? null }));
|
|
5386
|
+
}
|
|
5387
|
+
async userByName(token, username) {
|
|
5388
|
+
const found = await this.client.get(token, `users?username=${encodeURIComponent(username)}`);
|
|
5389
|
+
if (!found[0])
|
|
5390
|
+
throw Object.assign(new Error(`${username} is not a user of this GitLab`), { status: 404 });
|
|
5391
|
+
return found[0];
|
|
5392
|
+
}
|
|
5245
5393
|
async getFile({ token, id, path, ref }) {
|
|
5246
5394
|
return toFile(await this.session.getFile(token, id, path, ref));
|
|
5247
5395
|
}
|
|
@@ -5446,6 +5594,10 @@ class GitLabProvider {
|
|
|
5446
5594
|
const notes = await this.client.listPaged(token, `projects/${idOf(id)}/issues/${number}/notes?sort=asc&order_by=created_at`);
|
|
5447
5595
|
return notes.filter((note) => !note.system).map(toComment);
|
|
5448
5596
|
}
|
|
5597
|
+
async listIssueLabelEvents({ token, id, number }) {
|
|
5598
|
+
const events = await this.client.listPaged(token, `projects/${idOf(id)}/issues/${number}/resource_label_events`);
|
|
5599
|
+
return events.filter((event) => event.label?.name).map((event) => ({ label: event.label.name, action: event.action === "remove" ? "removed" : "added", author: event.user?.username, createdAt: event.created_at })).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
5600
|
+
}
|
|
5449
5601
|
async addIssueComment({ token, id, number, body }) {
|
|
5450
5602
|
return toComment(await this.client.send(token, "POST", `projects/${idOf(id)}/issues/${number}/notes`, { body }));
|
|
5451
5603
|
}
|
|
@@ -5691,16 +5843,6 @@ import path2 from "path";
|
|
|
5691
5843
|
import { spawn as spawn2 } from "child_process";
|
|
5692
5844
|
import { PassThrough } from "stream";
|
|
5693
5845
|
|
|
5694
|
-
// ../git/dist/access.js
|
|
5695
|
-
var ACCESS = {
|
|
5696
|
-
MINIMAL: 5,
|
|
5697
|
-
GUEST: 10,
|
|
5698
|
-
REPORTER: 20,
|
|
5699
|
-
DEVELOPER: 30,
|
|
5700
|
-
MAINTAINER: 40,
|
|
5701
|
-
OWNER: 50
|
|
5702
|
-
};
|
|
5703
|
-
|
|
5704
5846
|
// ../git/dist/closing.js
|
|
5705
5847
|
var REFERENCES = /\b(?:clos(?:e[sd]?|ing)|fix(?:e[sd]|ing)?|resolv(?:e[sd]?|ing)|implement(?:s|ed|ing)?)\b:?[ \t]+(#\d+(?:[ \t]*(?:,|and|&)[ \t]*#\d+)*)/gi;
|
|
5706
5848
|
var closingIssueNumbers = (...texts) => {
|
|
@@ -6346,6 +6488,27 @@ class LocalProvider {
|
|
|
6346
6488
|
members.set(member.username, member.accessLevel);
|
|
6347
6489
|
return [...members].map(([username, accessLevel]) => ({ username, accessLevel }));
|
|
6348
6490
|
}
|
|
6491
|
+
async listAccess({ token, id }) {
|
|
6492
|
+
return (await this.getMembers({ token, id })).map((member) => ({ ...member, source: "direct" }));
|
|
6493
|
+
}
|
|
6494
|
+
async setAccess({ token, id, username, accessLevel }) {
|
|
6495
|
+
await this.setMember({ token, id, username, accessLevel });
|
|
6496
|
+
}
|
|
6497
|
+
async removeAccess({ token, id, username }) {
|
|
6498
|
+
await this.removeMember({ token, id, username });
|
|
6499
|
+
}
|
|
6500
|
+
async searchUsers({ token, query }) {
|
|
6501
|
+
await this.user(token);
|
|
6502
|
+
const state = await this.store.read((current) => current);
|
|
6503
|
+
const names = new Set;
|
|
6504
|
+
for (const repository of state.repositories) {
|
|
6505
|
+
names.add(repository.owner);
|
|
6506
|
+
for (const member of repository.members)
|
|
6507
|
+
names.add(member.username);
|
|
6508
|
+
}
|
|
6509
|
+
const needle = query.trim().toLowerCase();
|
|
6510
|
+
return [...names].filter((name) => name.toLowerCase().includes(needle)).slice(0, 10).map((username) => ({ username, name: username, avatarUrl: null }));
|
|
6511
|
+
}
|
|
6349
6512
|
async getAccessLevel({ token, id, username }) {
|
|
6350
6513
|
await this.user(token);
|
|
6351
6514
|
const state = await this.store.read((current) => current);
|
|
@@ -6729,6 +6892,7 @@ class LocalProvider {
|
|
|
6729
6892
|
comments: [],
|
|
6730
6893
|
nextComment: 1
|
|
6731
6894
|
};
|
|
6895
|
+
issue.labelEvents = this.labelChanges([], issue.labels, user.username, now);
|
|
6732
6896
|
repository.nextIssue = issue.number + 1;
|
|
6733
6897
|
repository.issues = [...repository.issues ?? [], issue];
|
|
6734
6898
|
return issue;
|
|
@@ -6749,8 +6913,11 @@ class LocalProvider {
|
|
|
6749
6913
|
}
|
|
6750
6914
|
if (changes.description !== undefined)
|
|
6751
6915
|
issue.description = changes.description;
|
|
6752
|
-
if (changes.labels !== undefined)
|
|
6753
|
-
|
|
6916
|
+
if (changes.labels !== undefined) {
|
|
6917
|
+
const labels = this.cleanList(changes.labels);
|
|
6918
|
+
issue.labelEvents = [...issue.labelEvents ?? [], ...this.labelChanges(issue.labels, labels, user.username, new Date().toISOString())];
|
|
6919
|
+
issue.labels = labels;
|
|
6920
|
+
}
|
|
6754
6921
|
if (changes.assignees !== undefined)
|
|
6755
6922
|
issue.assignees = this.cleanList(changes.assignees);
|
|
6756
6923
|
if (changes.milestone !== undefined)
|
|
@@ -6825,6 +6992,16 @@ class LocalProvider {
|
|
|
6825
6992
|
toComment(record) {
|
|
6826
6993
|
return { id: record.id, author: record.author, body: record.body, createdAt: record.createdAt, updatedAt: record.updatedAt };
|
|
6827
6994
|
}
|
|
6995
|
+
labelChanges(before, after, author, at) {
|
|
6996
|
+
return [
|
|
6997
|
+
...before.filter((label) => !after.includes(label)).map((label) => ({ label, action: "removed", author, createdAt: at })),
|
|
6998
|
+
...after.filter((label) => !before.includes(label)).map((label) => ({ label, action: "added", author, createdAt: at }))
|
|
6999
|
+
];
|
|
7000
|
+
}
|
|
7001
|
+
async listIssueLabelEvents({ token, id, number }) {
|
|
7002
|
+
const { record } = await this.open(token, id);
|
|
7003
|
+
return (this.issueOf(record, number).labelEvents ?? []).map((event) => ({ ...event }));
|
|
7004
|
+
}
|
|
6828
7005
|
async listIssueComments({ token, id, number }) {
|
|
6829
7006
|
const { record } = await this.open(token, id);
|
|
6830
7007
|
return this.issueOf(record, number).comments.map((comment) => this.toComment(comment));
|
|
@@ -8904,6 +9081,9 @@ var config = {
|
|
|
8904
9081
|
get DEV_TOKEN() {
|
|
8905
9082
|
return process.env["LINEA_TOKEN"] ?? "";
|
|
8906
9083
|
},
|
|
9084
|
+
get MODE() {
|
|
9085
|
+
return process.env["LINEA_MODE"] ?? "";
|
|
9086
|
+
},
|
|
8907
9087
|
get LOOPBACK_PORT() {
|
|
8908
9088
|
return Number(process.env["LINEA_OAUTH_PORT"] ?? 53682);
|
|
8909
9089
|
}
|
|
@@ -8943,13 +9123,19 @@ function saveState(patch) {
|
|
|
8943
9123
|
write(next);
|
|
8944
9124
|
return next;
|
|
8945
9125
|
}
|
|
9126
|
+
function resolveMode(state = loadState()) {
|
|
9127
|
+
const asked = process.env["LINEA_MODE"];
|
|
9128
|
+
if (asked === "server" || asked === "offline")
|
|
9129
|
+
return asked;
|
|
9130
|
+
return state.mode ?? (state.token || config.DEV_TOKEN ? "server" : "offline");
|
|
9131
|
+
}
|
|
8946
9132
|
function clearAuth() {
|
|
8947
|
-
const { baseUrl, workdir, editor, theme, layout } = loadState();
|
|
8948
|
-
write({ baseUrl, workdir, editor, theme, layout });
|
|
9133
|
+
const { mode, baseUrl, workdir, editor, theme, layout } = loadState();
|
|
9134
|
+
write({ ...mode ? { mode } : {}, baseUrl, workdir, editor, theme, layout });
|
|
8949
9135
|
}
|
|
8950
9136
|
|
|
8951
9137
|
// src/core/git.ts
|
|
8952
|
-
var hostLabel = (provider) => provider === "github" ? "GitHub" : provider === "local" ? "LINEA" : "GitLab";
|
|
9138
|
+
var hostLabel = (provider) => provider === "github" ? "GitHub" : provider === "local" ? "LINEA git" : "GitLab";
|
|
8953
9139
|
function gitToken(config, env = process.env) {
|
|
8954
9140
|
return env["LINEA_GIT_TOKEN"] ?? (config.provider === "github" ? env["GITHUB_TOKEN"] : env["GITLAB_TOKEN"]);
|
|
8955
9141
|
}
|
|
@@ -9068,4 +9254,4 @@ function traceHelper2(op, request, answer) {
|
|
|
9068
9254
|
} catch {}
|
|
9069
9255
|
}
|
|
9070
9256
|
|
|
9071
|
-
export { createGitProvider, registerLocation, createPackageSource, publishFolder, git, gitAsync, isAuthFailure, checkGitAccess, isRepo, cloneUrlOf, credentialOptions, repoState, changedCount, checkoutsAt, cloneLine, cloneProduct, pullCheckout, fetchCheckout, pushCheckout, hasUnsent, adoptFolder, clonePackage, config, serverOf, loadState, saveState, clearAuth, hostLabel, gitConfigOf, gitSettings, gitProviderOf, catalogOf, remotePackages, packageSourceOf, credentialHelper2, whyNoAccess2, traceHelper2 };
|
|
9257
|
+
export { createGitProvider, registerLocation, createPackageSource, publishFolder, git, gitAsync, isAuthFailure, checkGitAccess, isRepo, cloneUrlOf, credentialOptions, repoState, changedCount, checkoutsAt, cloneLine, cloneProduct, pullCheckout, fetchCheckout, pushCheckout, hasUnsent, adoptFolder, clonePackage, config, serverOf, storedGit, loadState, saveState, resolveMode, clearAuth, hostLabel, gitConfigOf, gitSettings, gitProviderOf, catalogOf, remotePackages, packageSourceOf, credentialHelper2, whyNoAccess2, traceHelper2 };
|