@procedures/gh 0.2.3 → 0.4.0

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +28 -1
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/module.d.ts +2 -1
  5. package/dist/module.d.ts.map +1 -1
  6. package/dist/module.js +43 -1
  7. package/dist/module.js.map +1 -1
  8. package/dist/procedures/gh/api.d.ts +27 -0
  9. package/dist/procedures/gh/api.d.ts.map +1 -0
  10. package/dist/procedures/gh/api.js +114 -0
  11. package/dist/procedures/gh/api.js.map +1 -0
  12. package/dist/procedures/gh/index.d.ts +3 -0
  13. package/dist/procedures/gh/index.d.ts.map +1 -1
  14. package/dist/procedures/gh/index.js +3 -0
  15. package/dist/procedures/gh/index.js.map +1 -1
  16. package/dist/procedures/gh/run/download.d.ts +14 -0
  17. package/dist/procedures/gh/run/download.d.ts.map +1 -0
  18. package/dist/procedures/gh/run/download.js +23 -0
  19. package/dist/procedures/gh/run/download.js.map +1 -0
  20. package/dist/procedures/gh/shared.d.ts +10 -2
  21. package/dist/procedures/gh/shared.d.ts.map +1 -1
  22. package/dist/procedures/gh/shared.js +16 -2
  23. package/dist/procedures/gh/shared.js.map +1 -1
  24. package/dist/procedures/gh/workflow/run.d.ts +13 -0
  25. package/dist/procedures/gh/workflow/run.d.ts.map +1 -0
  26. package/dist/procedures/gh/workflow/run.js +29 -0
  27. package/dist/procedures/gh/workflow/run.js.map +1 -0
  28. package/dist/types.d.ts +51 -0
  29. package/dist/types.d.ts.map +1 -1
  30. package/package.json +4 -4
  31. package/src/module.ts +67 -1
  32. package/src/procedures/gh/api.ts +99 -0
  33. package/src/procedures/gh/index.ts +3 -0
  34. package/src/procedures/gh/run/download.ts +23 -0
  35. package/src/procedures/gh/shared.ts +16 -2
  36. package/src/procedures/gh/workflow/run.ts +30 -0
  37. package/src/types.ts +57 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,73 @@
1
+ # @procedures/gh
2
+
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 2c02cf0: Three new procedures: `gh.workflow.run`, `gh.run.download` and `gh.api`.
8
+
9
+ - `gh.workflow.run` starts a workflow run on a ref, with each input as `-f key=value`. When `gh` prints the URL of the new run, the output has `url` and `run`. It declares `writes: ["network"]`, and it is not destructive.
10
+ - `gh.run.download` downloads the artifacts of a run into `dir`, by `names` or `patterns`. It declares `writes: ["fs"]`. `gh` does not replace a file that exists, so it is not destructive.
11
+ - `gh.api` sends a request to the GitHub API and gives the parsed JSON as `data`. It always sends `--method` (default `GET`). A string field goes as `-f`, another value as `-F`. A JSON `body` goes as `--input` from a temporary file. `paginate` joins the pages of an array. `repo` goes to `gh` as `GH_REPO`.
12
+ - The method of `gh.api` is an input, and `PUT` or `DELETE` can replace or remove data. Thus `gh.api` declares `writes: ["network"]` and is destructive.
13
+
14
+ These procedures are not MCP tools.
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [d919678]
19
+ - Updated dependencies [057d69a]
20
+ - Updated dependencies [b2a1a1e]
21
+ - Updated dependencies [057d69a]
22
+ - Updated dependencies [057d69a]
23
+ - Updated dependencies [057d69a]
24
+ - Updated dependencies [057d69a]
25
+ - Updated dependencies [057d69a]
26
+ - Updated dependencies [afd6a19]
27
+ - Updated dependencies [057d69a]
28
+ - Updated dependencies [4c51727]
29
+ - Updated dependencies [4e751da]
30
+ - @procedures/client@0.4.0
31
+ - @procedures/shell@0.4.0
32
+
33
+ ## 0.3.0
34
+
35
+ ### Minor Changes
36
+
37
+ - 49de6a8: The GitHub CLI as procedures (roadmap R42). `@procedures/gh` has 13 procedures for pull requests, workflow runs, releases and issues: `gh.pr.list`, `gh.pr.view`, `gh.pr.checks`, `gh.pr.create`, `gh.run.list`, `gh.run.view`, `gh.run.rerun`, `gh.release.list`, `gh.release.view`, `gh.issue.list`, `gh.issue.view`, `gh.issue.create` and `gh.issue.comment`. Each one runs `gh` through `shell.run` with an argument list and no shell, and gives the JSON of `gh --json`. The reads change nothing. The writes declare `writes: ["network"]`.
38
+
39
+ ### Patch Changes
40
+
41
+ - Updated dependencies [ddea529]
42
+ - Updated dependencies [b2a3e3a]
43
+ - Updated dependencies [a8c47f1]
44
+ - Updated dependencies [381ce3a]
45
+ - Updated dependencies [0c627f8]
46
+ - Updated dependencies [ae7f05f]
47
+ - Updated dependencies [7873940]
48
+ - Updated dependencies [a70d445]
49
+ - Updated dependencies [bc70357]
50
+ - Updated dependencies [07cc998]
51
+ - Updated dependencies [a6b01a9]
52
+ - Updated dependencies [c799cdd]
53
+ - Updated dependencies [540f8d9]
54
+ - Updated dependencies [b6daaec]
55
+ - Updated dependencies [5b9264e]
56
+ - Updated dependencies [956e88b]
57
+ - Updated dependencies [ff62281]
58
+ - Updated dependencies [d81d0ed]
59
+ - Updated dependencies [aa67cc7]
60
+ - Updated dependencies [061fa22]
61
+ - Updated dependencies [cfb9d69]
62
+ - Updated dependencies [43f7de5]
63
+ - Updated dependencies [b07bb50]
64
+ - Updated dependencies [4a3bfa1]
65
+ - Updated dependencies [bd0b626]
66
+ - Updated dependencies [a6be873]
67
+ - Updated dependencies [fb30718]
68
+ - Updated dependencies [c5528e4]
69
+ - Updated dependencies [fee5d9c]
70
+ - Updated dependencies [21f7743]
71
+ - Updated dependencies [31a0b46]
72
+ - @procedures/client@0.3.0
73
+ - @procedures/shell@0.3.0
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  npm install @procedures/gh
7
7
  ```
8
8
 
9
- The GitHub CLI (`gh`) as procedures: pull requests, workflow runs, releases and issues. Each procedure runs `gh` through `shell.run` of `@procedures/shell`, with an argument list and no shell. The output is the JSON of `gh --json`.
9
+ The GitHub CLI (`gh`) as procedures: pull requests, workflow runs, artifacts, releases, issues and the GitHub API. Each procedure runs `gh` through `shell.run` of `@procedures/shell`, with an argument list and no shell. The output is the JSON of `gh --json`.
10
10
 
11
11
  `gh` must be on the `PATH`, with a login (`gh auth login`).
12
12
 
@@ -21,18 +21,40 @@ The GitHub CLI (`gh`) as procedures: pull requests, workflow runs, releases and
21
21
  | `gh.run.list` | The workflow runs: workflow, branch, status, limit | reads |
22
22
  | `gh.run.view` | One workflow run with its jobs | reads |
23
23
  | `gh.run.rerun` | Run a workflow run again, or only its failed jobs | writes |
24
+ | `gh.run.download` | Download the artifacts of a run: names, patterns, folder | writes `fs` |
25
+ | `gh.workflow.run` | Start a workflow run: workflow, ref, inputs | writes |
24
26
  | `gh.release.list` | The releases of a repository | reads |
25
27
  | `gh.release.view` | The release of a tag, or the latest release | reads |
26
28
  | `gh.issue.list` | The issues: state, label, author, search, limit | reads |
27
29
  | `gh.issue.view` | One issue, with its comments | reads |
28
30
  | `gh.issue.create` | Open an issue | writes |
29
31
  | `gh.issue.comment` | Add a comment to an issue or a pull request | writes |
32
+ | `gh.api` | Send a request to the GitHub API: endpoint, method, fields, body, paginate | writes, destructive |
30
33
 
31
34
  - A read declares `reads: ["network"]` and changes nothing. A write declares `writes: ["network"]`. It makes something new, so it is not destructive, and a second call makes a second one.
32
35
  - Each procedure takes `repo` (owner/name), `cwd` and `timeoutMs`. Without `repo`, `gh` uses the repository of the folder.
33
36
  - A value that `gh` reads as an argument (a number, a branch, a label) must not start with `-`. A title or a body is the value of its option, so it can start with `-`.
34
37
  - A failed command throws an error with the exit code and the text of `gh`. `gh.pr.checks` reports a pending check as an error that tells you to ask again.
35
38
 
39
+ ### Workflow runs and artifacts
40
+
41
+ - `gh.workflow.run` sends each input as `-f key=value`. When GitHub gives the new run, `gh` prints its URL. Then the output has `url` and `run`, the id of the run.
42
+ - Without `run` in the output, find the run with `gh.run.list`. Use the `workflow` and `branch` filters.
43
+ - `gh.run.download` writes the files of the artifacts into `dir`. It declares `writes: ["fs"]`.
44
+ - `gh` puts each artifact in a folder with its name. When the input selects one artifact, the files go directly into `dir`.
45
+ - `gh` does not replace a file that exists. The download then fails. Thus the procedure is not destructive.
46
+
47
+ ### The GitHub API
48
+
49
+ - `gh.api` always sends `--method`. The default is `GET`. Without this option, `gh` changes `GET` to `POST` when the call has fields.
50
+ - A string field goes as `-f`, and `gh` sends it as text. A number, a boolean or `null` goes as `-F`, and `gh` converts its type.
51
+ - `GET` sends the fields in the query. The other methods send them in the JSON body.
52
+ - `body` is a JSON value. The procedure writes it to a temporary file for `--input`, and removes the file after the call.
53
+ - `gh api` has no `--repo` option. The procedure gives `repo` to `gh` as `GH_REPO`. Then `gh` replaces `{owner}` and `{repo}` in the endpoint.
54
+ - The output is `{ data }`, the parsed JSON. An empty response (HTTP 204) gives `null`.
55
+ - With `paginate: true`, the pages of an array become one array. The pages of an object become an array of the pages.
56
+ - The method is an input, and `PUT` or `DELETE` can replace or remove data. Thus `gh.api` declares `writes: ["network"]` and keeps the default: destructive.
57
+
36
58
  ## Use
37
59
 
38
60
  ```typescript
@@ -47,6 +69,11 @@ const { items } = await client.exec(["gh", "run", "list"], { repo: "owner/name",
47
69
  mark gh run list --repo owner/name --status failure
48
70
  ```
49
71
 
72
+ ```typescript
73
+ const { run } = await client.exec(["gh", "workflow", "run"], { workflow: "ci.yml", ref: "main", inputs: { shards: "4" } });
74
+ const { data } = await client.exec(["gh", "api"], { endpoint: "repos/{owner}/{repo}/pulls", repo: "owner/name", paginate: true });
75
+ ```
76
+
50
77
  ## Tests
51
78
 
52
79
  `pnpm --filter @procedures/gh test` runs the procedures with a fake shell. The tests examine each argument list, the JSON of `gh`, the failures and the values that cannot become options.