sarif-to-comment 0.1.0 → 0.2.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 (203) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +52 -7
  3. package/bin/sarif-to-comment.cjs +7 -253
  4. package/docs/api/index.md +1 -1
  5. package/docs/api/sarif-to-comment.addsarifcomment.md +91 -0
  6. package/docs/api/sarif-to-comment.addsarifcommentoutcome.md +15 -0
  7. package/docs/api/sarif-to-comment.addstagedchangesoutcome.md +15 -0
  8. package/docs/api/sarif-to-comment.addstagedchangestosarif.md +66 -0
  9. package/docs/api/sarif-to-comment.createsarifdocument.md +73 -0
  10. package/docs/api/sarif-to-comment.iaddedfinding.md +123 -0
  11. package/docs/api/sarif-to-comment.iaddedfinding.ref.md +13 -0
  12. package/docs/api/sarif-to-comment.iaddedfinding.resultindex.md +13 -0
  13. package/docs/api/sarif-to-comment.iaddedfinding.runindex.md +13 -0
  14. package/docs/api/sarif-to-comment.iaddedfinding.tool.md +13 -0
  15. package/docs/api/sarif-to-comment.iaddedsarifcommentoutcome.finding.md +13 -0
  16. package/docs/api/sarif-to-comment.iaddedsarifcommentoutcome.md +102 -0
  17. package/docs/api/sarif-to-comment.iaddedsarifcommentoutcome.sarif.md +13 -0
  18. package/docs/api/sarif-to-comment.iaddedsarifcommentoutcome.status.md +13 -0
  19. package/docs/api/sarif-to-comment.iaddedstagedchangesoutcome.md +102 -0
  20. package/docs/api/sarif-to-comment.iaddedstagedchangesoutcome.receipt.md +13 -0
  21. package/docs/api/sarif-to-comment.iaddedstagedchangesoutcome.sarif.md +13 -0
  22. package/docs/api/sarif-to-comment.iaddedstagedchangesoutcome.status.md +13 -0
  23. package/docs/api/sarif-to-comment.iaddstagedchangesinput.md +144 -0
  24. package/docs/api/sarif-to-comment.iaddstagedchangesinput.repository.md +13 -0
  25. package/docs/api/sarif-to-comment.iaddstagedchangesinput.reviewedcommit.md +13 -0
  26. package/docs/api/sarif-to-comment.iaddstagedchangesinput.sarif.md +13 -0
  27. package/docs/api/sarif-to-comment.iaddstagedchangesinput.sourcerooturi.md +13 -0
  28. package/docs/api/sarif-to-comment.iaddstagedchangesinput.worktree.md +13 -0
  29. package/docs/api/sarif-to-comment.icreatesarifdocumentoptions.md +81 -0
  30. package/docs/api/sarif-to-comment.icreatesarifdocumentoptions.source.md +13 -0
  31. package/docs/api/sarif-to-comment.icreatesarifdocumentoptions.tool.md +13 -0
  32. package/docs/api/sarif-to-comment.ifailedstagedchangesoutcome.markdown.md +13 -0
  33. package/docs/api/sarif-to-comment.ifailedstagedchangesoutcome.md +102 -0
  34. package/docs/api/sarif-to-comment.ifailedstagedchangesoutcome.problems.md +13 -0
  35. package/docs/api/sarif-to-comment.ifailedstagedchangesoutcome.status.md +13 -0
  36. package/docs/api/sarif-to-comment.igithubrepository.md +81 -0
  37. package/docs/api/sarif-to-comment.igithubrepository.owner.md +13 -0
  38. package/docs/api/sarif-to-comment.igithubrepository.repo.md +13 -0
  39. package/docs/api/sarif-to-comment.iinspectedoutcome.md +81 -0
  40. package/docs/api/sarif-to-comment.iinspectedoutcome.status.md +13 -0
  41. package/docs/api/sarif-to-comment.iinspectedoutcome.view.md +13 -0
  42. package/docs/api/sarif-to-comment.iinspectionartifactchange.artifactlocation.md +13 -0
  43. package/docs/api/sarif-to-comment.iinspectionartifactchange.md +144 -0
  44. package/docs/api/sarif-to-comment.iinspectionartifactchange.othercontent.md +13 -0
  45. package/docs/api/sarif-to-comment.iinspectionartifactchange.path.md +13 -0
  46. package/docs/api/sarif-to-comment.iinspectionartifactchange.replacements.md +13 -0
  47. package/docs/api/sarif-to-comment.iinspectionartifactchange.uri.md +13 -0
  48. package/docs/api/sarif-to-comment.iinspectiondiagnostic.md +102 -0
  49. package/docs/api/sarif-to-comment.iinspectiondiagnostic.message.md +13 -0
  50. package/docs/api/sarif-to-comment.iinspectiondiagnostic.pointer.md +13 -0
  51. package/docs/api/sarif-to-comment.iinspectiondiagnostic.severity.md +13 -0
  52. package/docs/api/sarif-to-comment.iinspectionexternalproperties.content.md +13 -0
  53. package/docs/api/sarif-to-comment.iinspectionexternalproperties.md +106 -0
  54. package/docs/api/sarif-to-comment.iinspectionexternalproperties.ref.md +13 -0
  55. package/docs/api/sarif-to-comment.iinspectionexternalproperties.results.md +13 -0
  56. package/docs/api/sarif-to-comment.iinspectionfileproposal.artifactindex.md +13 -0
  57. package/docs/api/sarif-to-comment.iinspectionfileproposal.content.md +13 -0
  58. package/docs/api/sarif-to-comment.iinspectionfileproposal.filemode.md +13 -0
  59. package/docs/api/sarif-to-comment.iinspectionfileproposal.md +186 -0
  60. package/docs/api/sarif-to-comment.iinspectionfileproposal.operation.md +13 -0
  61. package/docs/api/sarif-to-comment.iinspectionfileproposal.othercontent.md +13 -0
  62. package/docs/api/sarif-to-comment.iinspectionfileproposal.path.md +13 -0
  63. package/docs/api/sarif-to-comment.iinspectionfileproposal.ref.md +13 -0
  64. package/docs/api/sarif-to-comment.iinspectionfinding.approval.md +13 -0
  65. package/docs/api/sarif-to-comment.iinspectionfinding.baselinestate.md +13 -0
  66. package/docs/api/sarif-to-comment.iinspectionfinding.fileproposals.md +13 -0
  67. package/docs/api/sarif-to-comment.iinspectionfinding.fixes.md +13 -0
  68. package/docs/api/sarif-to-comment.iinspectionfinding.kind.md +13 -0
  69. package/docs/api/sarif-to-comment.iinspectionfinding.level.md +13 -0
  70. package/docs/api/sarif-to-comment.iinspectionfinding.locations.md +13 -0
  71. package/docs/api/sarif-to-comment.iinspectionfinding.md +333 -0
  72. package/docs/api/sarif-to-comment.iinspectionfinding.message.md +13 -0
  73. package/docs/api/sarif-to-comment.iinspectionfinding.othercontent.md +13 -0
  74. package/docs/api/sarif-to-comment.iinspectionfinding.ref.md +13 -0
  75. package/docs/api/sarif-to-comment.iinspectionfinding.relatedlocations.md +13 -0
  76. package/docs/api/sarif-to-comment.iinspectionfinding.resultindex.md +13 -0
  77. package/docs/api/sarif-to-comment.iinspectionfinding.ruleid.md +13 -0
  78. package/docs/api/sarif-to-comment.iinspectionfinding.runindex.md +13 -0
  79. package/docs/api/sarif-to-comment.iinspectionfix.changes.md +13 -0
  80. package/docs/api/sarif-to-comment.iinspectionfix.description.md +13 -0
  81. package/docs/api/sarif-to-comment.iinspectionfix.descriptioncontent.md +13 -0
  82. package/docs/api/sarif-to-comment.iinspectionfix.md +144 -0
  83. package/docs/api/sarif-to-comment.iinspectionfix.othercontent.md +13 -0
  84. package/docs/api/sarif-to-comment.iinspectionfix.ref.md +13 -0
  85. package/docs/api/sarif-to-comment.iinspectionlocation.artifactlocation.md +13 -0
  86. package/docs/api/sarif-to-comment.iinspectionlocation.charlength.md +13 -0
  87. package/docs/api/sarif-to-comment.iinspectionlocation.charoffset.md +13 -0
  88. package/docs/api/sarif-to-comment.iinspectionlocation.endcolumn.md +13 -0
  89. package/docs/api/sarif-to-comment.iinspectionlocation.endline.md +13 -0
  90. package/docs/api/sarif-to-comment.iinspectionlocation.logical.md +13 -0
  91. package/docs/api/sarif-to-comment.iinspectionlocation.md +354 -0
  92. package/docs/api/sarif-to-comment.iinspectionlocation.message.md +13 -0
  93. package/docs/api/sarif-to-comment.iinspectionlocation.messagecontent.md +13 -0
  94. package/docs/api/sarif-to-comment.iinspectionlocation.othercontent.md +13 -0
  95. package/docs/api/sarif-to-comment.iinspectionlocation.path.md +13 -0
  96. package/docs/api/sarif-to-comment.iinspectionlocation.snippet.md +13 -0
  97. package/docs/api/sarif-to-comment.iinspectionlocation.startcolumn.md +13 -0
  98. package/docs/api/sarif-to-comment.iinspectionlocation.startline.md +13 -0
  99. package/docs/api/sarif-to-comment.iinspectionlocation.uri.md +13 -0
  100. package/docs/api/sarif-to-comment.iinspectionlocation.uribaseid.md +13 -0
  101. package/docs/api/sarif-to-comment.iinspectionmessage.arguments.md +13 -0
  102. package/docs/api/sarif-to-comment.iinspectionmessage.id.md +13 -0
  103. package/docs/api/sarif-to-comment.iinspectionmessage.markdown.md +13 -0
  104. package/docs/api/sarif-to-comment.iinspectionmessage.md +165 -0
  105. package/docs/api/sarif-to-comment.iinspectionmessage.othercontent.md +13 -0
  106. package/docs/api/sarif-to-comment.iinspectionmessage.resolved.md +13 -0
  107. package/docs/api/sarif-to-comment.iinspectionmessage.text.md +13 -0
  108. package/docs/api/sarif-to-comment.iinspectionpreview.bytelength.md +13 -0
  109. package/docs/api/sarif-to-comment.iinspectionpreview.md +207 -0
  110. package/docs/api/sarif-to-comment.iinspectionpreview.othercontent.md +13 -0
  111. package/docs/api/sarif-to-comment.iinspectionpreview.shownchars.md +13 -0
  112. package/docs/api/sarif-to-comment.iinspectionpreview.shownlines.md +13 -0
  113. package/docs/api/sarif-to-comment.iinspectionpreview.state.md +13 -0
  114. package/docs/api/sarif-to-comment.iinspectionpreview.text.md +13 -0
  115. package/docs/api/sarif-to-comment.iinspectionpreview.totalchars.md +13 -0
  116. package/docs/api/sarif-to-comment.iinspectionpreview.totallines.md +13 -0
  117. package/docs/api/sarif-to-comment.iinspectionreplacement.deletedregion.md +13 -0
  118. package/docs/api/sarif-to-comment.iinspectionreplacement.inserted.md +13 -0
  119. package/docs/api/sarif-to-comment.iinspectionreplacement.md +102 -0
  120. package/docs/api/sarif-to-comment.iinspectionreplacement.othercontent.md +13 -0
  121. package/docs/api/sarif-to-comment.iinspectionrun.approval.md +13 -0
  122. package/docs/api/sarif-to-comment.iinspectionrun.columnkind.md +13 -0
  123. package/docs/api/sarif-to-comment.iinspectionrun.index.md +13 -0
  124. package/docs/api/sarif-to-comment.iinspectionrun.md +186 -0
  125. package/docs/api/sarif-to-comment.iinspectionrun.othercontent.md +13 -0
  126. package/docs/api/sarif-to-comment.iinspectionrun.ref.md +13 -0
  127. package/docs/api/sarif-to-comment.iinspectionrun.source.md +13 -0
  128. package/docs/api/sarif-to-comment.iinspectionrun.tool.md +13 -0
  129. package/docs/api/sarif-to-comment.iinspectsarifoptions.md +102 -0
  130. package/docs/api/sarif-to-comment.iinspectsarifoptions.previewchars.md +13 -0
  131. package/docs/api/sarif-to-comment.iinspectsarifoptions.previewlines.md +13 -0
  132. package/docs/api/sarif-to-comment.iinspectsarifoptions.sourcerooturi.md +13 -0
  133. package/docs/api/sarif-to-comment.iinvalidsarifoutcome.markdown.md +13 -0
  134. package/docs/api/sarif-to-comment.iinvalidsarifoutcome.md +102 -0
  135. package/docs/api/sarif-to-comment.iinvalidsarifoutcome.problems.md +13 -0
  136. package/docs/api/sarif-to-comment.iinvalidsarifoutcome.status.md +13 -0
  137. package/docs/api/sarif-to-comment.inewsarifrun.md +102 -0
  138. package/docs/api/sarif-to-comment.inewsarifrun.source.md +13 -0
  139. package/docs/api/sarif-to-comment.inewsarifrun.toolname.md +13 -0
  140. package/docs/api/sarif-to-comment.inewsarifrun.toolversion.md +13 -0
  141. package/docs/api/sarif-to-comment.inspectsarif.md +80 -0
  142. package/docs/api/sarif-to-comment.inspectsarifoutcome.md +15 -0
  143. package/docs/api/sarif-to-comment.iproblem.md +102 -0
  144. package/docs/api/sarif-to-comment.iproblem.message.md +13 -0
  145. package/docs/api/sarif-to-comment.iproblem.path.md +13 -0
  146. package/docs/api/sarif-to-comment.iproblem.pointer.md +13 -0
  147. package/docs/api/sarif-to-comment.isarifcomment.endline.md +13 -0
  148. package/docs/api/sarif-to-comment.isarifcomment.file.md +13 -0
  149. package/docs/api/sarif-to-comment.isarifcomment.level.md +13 -0
  150. package/docs/api/sarif-to-comment.isarifcomment.line.md +13 -0
  151. package/docs/api/sarif-to-comment.isarifcomment.md +207 -0
  152. package/docs/api/sarif-to-comment.isarifcomment.message.md +13 -0
  153. package/docs/api/sarif-to-comment.isarifcomment.messageformat.md +13 -0
  154. package/docs/api/sarif-to-comment.isarifcomment.ruleid.md +13 -0
  155. package/docs/api/sarif-to-comment.isarifcomment.run.md +13 -0
  156. package/docs/api/sarif-to-comment.isarifinspection.diagnostics.md +13 -0
  157. package/docs/api/sarif-to-comment.isarifinspection.externalproperties.md +13 -0
  158. package/docs/api/sarif-to-comment.isarifinspection.findings.md +13 -0
  159. package/docs/api/sarif-to-comment.isarifinspection.format.md +13 -0
  160. package/docs/api/sarif-to-comment.isarifinspection.log.md +13 -0
  161. package/docs/api/sarif-to-comment.isarifinspection.md +207 -0
  162. package/docs/api/sarif-to-comment.isarifinspection.runs.md +13 -0
  163. package/docs/api/sarif-to-comment.isarifinspection.summary.md +20 -0
  164. package/docs/api/sarif-to-comment.isarifinspection.version.md +13 -0
  165. package/docs/api/sarif-to-comment.isariflog._schema.md +13 -0
  166. package/docs/api/sarif-to-comment.isariflog.md +100 -0
  167. package/docs/api/sarif-to-comment.isariflog.runs.md +13 -0
  168. package/docs/api/sarif-to-comment.isariflog.version.md +13 -0
  169. package/docs/api/sarif-to-comment.isarifsourcebinding.commit.md +13 -0
  170. package/docs/api/sarif-to-comment.isarifsourcebinding.md +61 -0
  171. package/docs/api/sarif-to-comment.isariftoolidentity.md +81 -0
  172. package/docs/api/sarif-to-comment.isariftoolidentity.name.md +13 -0
  173. package/docs/api/sarif-to-comment.isariftoolidentity.version.md +13 -0
  174. package/docs/api/sarif-to-comment.istagedchangereceipt.associated.md +13 -0
  175. package/docs/api/sarif-to-comment.istagedchangereceipt.explainedby.md +13 -0
  176. package/docs/api/sarif-to-comment.istagedchangereceipt.md +144 -0
  177. package/docs/api/sarif-to-comment.istagedchangereceipt.operation.md +13 -0
  178. package/docs/api/sarif-to-comment.istagedchangereceipt.path.md +13 -0
  179. package/docs/api/sarif-to-comment.istagedchangereceipt.replacements.md +13 -0
  180. package/docs/api/sarif-to-comment.istagedchangesreceipt.addedrun.md +13 -0
  181. package/docs/api/sarif-to-comment.istagedchangesreceipt.boundruns.md +13 -0
  182. package/docs/api/sarif-to-comment.istagedchangesreceipt.changes.md +13 -0
  183. package/docs/api/sarif-to-comment.istagedchangesreceipt.md +144 -0
  184. package/docs/api/sarif-to-comment.istagedchangesreceipt.reviewedcommit.md +13 -0
  185. package/docs/api/sarif-to-comment.istagedchangesreceipt.warnings.md +13 -0
  186. package/docs/api/sarif-to-comment.istagedreplacementreceipt.associated.md +13 -0
  187. package/docs/api/sarif-to-comment.istagedreplacementreceipt.endline.md +13 -0
  188. package/docs/api/sarif-to-comment.istagedreplacementreceipt.explainedby.md +13 -0
  189. package/docs/api/sarif-to-comment.istagedreplacementreceipt.insertion.md +13 -0
  190. package/docs/api/sarif-to-comment.istagedreplacementreceipt.md +148 -0
  191. package/docs/api/sarif-to-comment.istagedreplacementreceipt.startline.md +13 -0
  192. package/docs/api/sarif-to-comment.md +432 -2
  193. package/docs/getting-started.md +126 -3
  194. package/package.json +2 -2
  195. package/src/artifact-files.cjs +255 -0
  196. package/src/cli.cjs +927 -0
  197. package/src/index.cjs +27 -9
  198. package/src/sarif-authoring.cjs +230 -0
  199. package/src/sarif-common.cjs +589 -0
  200. package/src/sarif-inspection.cjs +677 -0
  201. package/src/staged-changes.cjs +1026 -0
  202. package/src/staged-git.cjs +367 -0
  203. package/types/index.d.ts +812 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # sarif-to-comment
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Write, inspect and extend SARIF without an analyzer, and turn staged Git changes into suggested fixes.
8
+
9
+ - New library functions `createSarifDocument`, `addSarifComment`, `inspectSarif` and `addStagedChangesToSarif`, with TypeScript declarations. They work on ordinary in-memory SARIF, never change their input, and accept SARIF from any producer.
10
+ - New CLI commands `init`, `add-comment`, `inspect`, `add-staged-changes` and `publish`.
11
+ - `--format human|json` on every command: JSON mode prints exactly one document for every outcome, errors included.
12
+ - `add-staged-changes` reads only the Git index, never unstaged working-tree content. It attaches a change to a finding only when the finding's lines lie within the change, and fails with an explanation for changes it cannot represent. An existing output file is preserved under a timestamped `.old.` name.
13
+ - Publishing is unchanged. The original flag-only command keeps its exact behavior, output and exit statuses.
14
+
15
+ ## 0.1.1
16
+
17
+ ### Patch Changes
18
+
19
+ - e3a0c2a: Correct the release documentation shipped in the README.
20
+
21
+ - Provenance is described conditionally. Trusted publishing authenticates with OIDC from a private or public repository, but npm attaches a provenance attestation only when the source repository is public at publish time. Version 0.1.0 carries a verified attestation; a release from a private repository has none.
22
+ - Release commits are no longer said to be recorded as `gitHead`, which is absent from the registry metadata for 0.1.0. The commit is identified by the `publish.yml` run and, when present, the provenance attestation; tags remain optional.
23
+
3
24
  ## 0.1.0
4
25
 
5
26
  ### Minor Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # sarif-to-comment
2
2
 
3
- Publish a ready [SARIF 2.1.0](https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html) document as **one GitHub draft pull request review**:
3
+ Write, inspect and publish [SARIF 2.1.0](https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/sarif-v2.1.0-errata01-os-complete.html) findings as **one GitHub draft pull request review**:
4
4
 
5
5
  - general feedback in the review body;
6
6
  - findings on changed lines as inline comments;
@@ -8,6 +8,13 @@ Publish a ready [SARIF 2.1.0](https://docs.oasis-open.org/sarif/sarif/v2.1.0/err
8
8
 
9
9
  It is sent in a single create-review request.
10
10
 
11
+ The SARIF can come from any analyzer. Or you can write it yourself, with no analyzer:
12
+ - create a document and add findings on lines or line ranges;
13
+ - add the changes you staged with Git as suggested fixes on those findings;
14
+ - inspect the result before publishing.
15
+
16
+ Every step reads and writes ordinary SARIF and is optional. SARIF from an analyzer can be inspected, given staged changes or published directly, without any setup step.
17
+
11
18
  The scope is deliberately narrow:
12
19
 
13
20
  - **One-way.** SARIF goes to GitHub once. The tool never updates, reconciles, submits, restores or deletes a review afterwards. Supplying a new SARIF document (with a new state path) creates a separate review.
@@ -15,13 +22,16 @@ The scope is deliberately narrow:
15
22
  - **Whole review or nothing.** If any finding can't be published faithfully, nothing is published, and the tool explains why.
16
23
  - **Never duplicated.** A durable state file makes retries confirm the existing review instead of creating another.
17
24
 
18
- Requires Node.js 22 or later. There are two surfaces, the **library** (SARIF in memory) and the **CLI** (a SARIF file); both run the same code.
25
+ Requires Node.js 22 or later. There are two surfaces, the **library** (SARIF in memory) and the **CLI** (SARIF files); both run the same code.
19
26
 
20
27
  ## Documentation
21
28
 
22
29
  These documents are included in the package. The links open them on unpkg (for the latest published version) and need no access to the source repository.
23
30
 
24
- - **[Getting started](https://unpkg.com/sarif-to-comment/docs/getting-started.md):** credentials, the reviewed commit, source root and state path, a complete library example and a complete CLI example, and how to handle every outcome.
31
+ - **[Getting started](https://unpkg.com/sarif-to-comment/docs/getting-started.md):**
32
+ - credentials, the reviewed commit, the source root and the state path;
33
+ - complete library and CLI examples for publishing an analyzer's SARIF, and for writing a review yourself from staged changes;
34
+ - how to handle every outcome.
25
35
  - **[API reference](https://unpkg.com/sarif-to-comment/docs/api/index.md):** generated by API Documenter from the package's TypeScript declarations.
26
36
  - **[Changelog](https://unpkg.com/sarif-to-comment/CHANGELOG.md):** release notes produced by Changesets.
27
37
 
@@ -91,7 +101,8 @@ GH_TOKEN=... npx sarif-to-comment \
91
101
  --state /var/lib/my-linter/reviews/acme-widgets-42-run-1817.json
92
102
  ```
93
103
 
94
- - **Optional flags:** `--source-root FILE_URI`, `--old-source-commit FULLSHA` and `--ignore-approval-hold`. Run `sarif-to-comment --help` for details; it needs no token and makes no request.
104
+ - **Optional flags:** `--source-root FILE_URI`, `--old-source-commit FULLSHA`, `--ignore-approval-hold` and `--format human|json`. Run `sarif-to-comment --help` for details; it needs no token and makes no request.
105
+ - **Command form:** `sarif-to-comment publish` followed by the same flags does exactly the same thing. With `--format json` either form prints one JSON document (`status`, `review`, `statePath` and the Markdown `message`), with the same exit status.
95
106
  - **Same core as the library:** the CLI reads the file, calls the same `publishSarifReview`, and prints the same Markdown to stdout.
96
107
  - **File encoding:** the SARIF file must be UTF-8 JSON.
97
108
  - A leading UTF-8 byte-order mark is ignored, so the CLI and a library caller passing the same parsed document produce the same publication.
@@ -104,6 +115,35 @@ GH_TOKEN=... npx sarif-to-comment \
104
115
  | 3 | uncertain: retry with the same `--state` |
105
116
  | 1 | usage error, unreadable or unparsable SARIF file, refused request, or operational failure (details on stderr) |
106
117
 
118
+ ## Quick start: write a review yourself
119
+
120
+ ```sh
121
+ # In the repository, with your proposed change staged (git add); unstaged edits are ignored.
122
+ npx sarif-to-comment init --output review.sarif --tool-name "Review agent"
123
+ npx sarif-to-comment add-comment --sarif review.sarif --file src/parse.js --line 2 \
124
+ --message "Handle the empty-input case."
125
+ npx sarif-to-comment add-staged-changes --sarif review.sarif --output review.staged.sarif \
126
+ --worktree . --repo acme/widgets --commit c0dec0dec0dec0dec0dec0dec0dec0dec0dec0de
127
+ npx sarif-to-comment inspect --sarif review.staged.sarif
128
+ GH_TOKEN=... npx sarif-to-comment publish --sarif review.staged.sarif --repo acme/widgets --pull 42 \
129
+ --commit c0dec0dec0dec0dec0dec0dec0dec0dec0dec0de --state /var/lib/reviews/acme-widgets-42.json
130
+ ```
131
+
132
+ The library has the same operations for in-memory SARIF: `createSarifDocument`, `addSarifComment`, `inspectSarif`, `addStagedChangesToSarif` and `publishSarifReview`. Each returns a new document or a view and never changes its input.
133
+
134
+ - **Line numbers** refer to the reviewed commit. For a file the reviewed commit doesn't have, they refer to its staged content.
135
+ - **Associating changes with findings.** Only the staged index is read. A staged change becomes a fix on a finding only when the finding's lines lie within the lines the change replaces; neither is enlarged.
136
+ - A finding that only partly overlaps a change stays a comment. The receipt says so.
137
+ - A change that no finding explains is kept as a short factual finding attributed to `sarif-to-comment`. A change that only adds lines replaces no reviewed line, so it is never credited to a nearby finding; the receipt marks it `insertion: true`.
138
+ - Findings that already have fixes are never changed. If your staged change differs from such a fix on the same lines, the command fails rather than choose between them.
139
+ - **Files.** `init` refuses to overwrite an existing file. `add-comment` updates its SARIF file in place, atomically. `add-staged-changes` writes a separate output; if that output file already exists, it's first renamed to `<UTC time>.old.<name>`, and a failed run writes no output.
140
+ - **Output.** `inspect` shows every finding in full, with its locations and fixes, plus log-level and inline external properties verbatim. Only fix previews are shortened, visibly. It doesn't check whether the file can be published.
141
+ - `--format json` on any command prints one JSON document for every outcome, errors included. Exit statuses are the same in both formats.
142
+ - Exit statuses: 0 success; 2 content refused (not valid SARIF, or a staged change that can't be represented); 1 usage or operational error. `publish` keeps the exit statuses below.
143
+ - **Changes that can't be represented.** Staged edits to UTF-8 text files become fixes. Publication still checks native-suggestion compatibility: empty reviewed files, or files containing only a byte-order mark, have no source line for an inline suggestion and are blocked. File creations and deletions become proposed file operations: `inspect` shows them, but `publish` doesn't support them yet and blocks the review. `add-staged-changes` fails, naming the path, for mode changes, symbolic links, submodules, binary or non-UTF-8 files, conflicts and intent-to-add entries.
144
+
145
+ See the [getting-started guide](https://unpkg.com/sarif-to-comment/docs/getting-started.md#write-a-review-yourself) for complete, tested examples of both surfaces and of SARIF from an analyzer.
146
+
107
147
  ## Credentials
108
148
 
109
149
  Use a GitHub **personal access token or user token**. It needs permission to read the repository and to create pull request reviews; for a fine-grained token that is *Contents: Read* and *Pull requests: Read and write*. The CLI reads `GH_TOKEN`, or else `GITHUB_TOKEN`; there is no token flag.
@@ -181,7 +221,8 @@ If that comparison can't establish the old side, you may pass `oldSourceCommit`
181
221
  - The durability steps (write, flush, then send) are ordered for crash safety, but that has not been tested against power loss.
182
222
  - GitHub Enterprise Server and GitHub App installation tokens are not supported.
183
223
  - There is no review maintenance, re-review or synchronisation back to SARIF.
184
- - Releases from the private source repository carry no npm provenance attestation (see [Releasing](#releasing)).
224
+ - Authoring can't yet remove or correct a finding in place, and there's no standalone check that a document can be published; `publish` performs every check. Staged file creations and deletions can be recorded in SARIF, but can't be published yet.
225
+ - npm attaches a provenance attestation only when the source repository is public at publish time. A release published while the repository is private has no provenance attestation (see [Releasing](#releasing)).
185
226
 
186
227
  ## Development
187
228
 
@@ -242,7 +283,11 @@ Changesets pre mode (prereleases) is not part of this release path.
242
283
 
243
284
  That commit changes `package.json`, so the workflow runs with the fixed code and publishes the new version. The version that failed stays unpublished; its changelog entry remains as history.
244
285
 
245
- The workflow publishes but does not create git tags. npm records the published commit (`gitHead`). Maintainers may run `pnpm changeset git-tag` locally and push the tags if they want them.
286
+ **Recording the release commit.** The workflow publishes the verified tarball but doesn't create git tags, and npm's registry metadata for 0.1.0 records no `gitHead`. Do not assume that field identifies a tarball release. The commit is identified in two places:
287
+ - by the successful `publish.yml` workflow run for that commit on `main`;
288
+ - when the repository is public at publish time, by the version's npm provenance attestation, which names the source repository, workflow and commit.
289
+
290
+ Maintainers who want tags can run `pnpm changeset git-tag` locally on that commit and push the tags.
246
291
 
247
292
  **First release.** The release history starts from npm's pre-existing `0.0.0`, the bootstrap baseline for this package. The initial `minor` changeset versions that baseline to **0.1.0**, with the first changelog entry, and 0.1.0 is the first version this workflow publishes. Later releases follow the same steps from whatever version `package.json` then holds.
248
293
 
@@ -259,4 +304,4 @@ On the package's **Settings → Trusted publishing** page, add a GitHub Actions
259
304
 
260
305
  npm requires `repository.url` in `package.json` to match this repository exactly. It is `git+https://github.com/mike-north/sarif-to-comment.git`. Once a trusted release has succeeded, npm recommends setting **Publishing access** to *Require two-factor authentication and disallow tokens*.
261
306
 
262
- **Provenance.** npm attaches provenance automatically only when the source repository is public. The source repository is private, so its releases carry no provenance attestation. The workflow deliberately does not pass `--provenance`, which would fail for a private repository. If the repository is made public, npm will add provenance with no workflow change.
307
+ **Provenance.** Trusted publishing authenticates with OIDC from a private or public repository alike. npm attaches a provenance attestation automatically only when the source repository is public at publish time; a release from a private repository has no provenance attestation. That limitation comes from npm, not from this workflow, and the workflow never changes repository visibility. Version 0.1.0 was published from the repository while it was public, and its npm provenance attestation verifies, naming commit `3797ca6efe2156d4c952fad7fed10b569f1dcbbb` and `.github/workflows/publish.yml`. The workflow deliberately does not pass `--provenance`, which fails for a private repository; npm adds provenance on its own whenever the repository is public.
@@ -2,263 +2,17 @@
2
2
  'use strict';
3
3
 
4
4
  /**
5
- * Thin command-line interface over publishSarifReview (src/index.cjs).
5
+ * The sarif-to-comment executable. All behavior lives in src/cli.cjs, which
6
+ * documents the commands, the flag-only publisher, output formats and exit
7
+ * statuses; this file only connects it to the process.
6
8
  *
7
- * Reads one SARIF JSON file, calls the same library operation library
8
- * consumers use, and prints that operation's Markdown. It has no rendering,
9
- * placement or delivery logic of its own: argument parsing, file reading,
10
- * credential selection and exit-status mapping are its only concerns.
11
- *
12
- * Usage:
13
- * sarif-to-comment --sarif FILE --repo OWNER/REPO --pull N --commit FULLSHA
14
- * --state ABSOLUTE_FILE [--source-root ABSOLUTE_FILE_URI]
15
- * [--old-source-commit FULLSHA] [--ignore-approval-hold]
16
- * sarif-to-comment --help
17
- *
18
- * Flags accept `--flag value` or `--flag=value`. Unknown, missing, valueless
19
- * or repeated flags and positional arguments are usage errors.
20
- * `--ignore-approval-hold` takes no value and bypasses only an approval hold.
21
- * There is no token flag and no reset/force-resend flag: `--state` is the
22
- * durable identity of one publication; retry with the same path.
23
- *
24
- * Credential: GH_TOKEN, else GITHUB_TOKEN (empty counts as unset). Both are
25
- * treated as user/PAT credentials; automatic Actions tokens are not claimed to
26
- * be supported. The token never appears in output; any occurrence in an error
27
- * is redacted. `--help` needs no token and makes no network call.
28
- *
29
- * Output and exit status:
30
- * stdout: the operation's Markdown for any outcome
31
- * stderr: usage, input-file and operational errors (actionable, redacted)
32
- * 0 published 2 blocked 3 uncertain
33
- * 1 usage error, unreadable/unparsable SARIF file, operational failure,
34
- * local state refusal, or GitHub refusal of the create request
35
- *
36
- * ---------------------------------------------------------------------------
37
- * main({ argv, env, stdout, stderr }, internals?) -> Promise<exitCode>
38
- * argv: arguments after the executable; env: environment variables;
39
- * stdout/stderr: writable streams. `internals` is passed through to
9
+ * main({ argv, env, stdout, stderr, stdin?, cwd? }, internals?) -> Promise<exitCode>
10
+ * Exported for the test wrappers; `internals` is passed through to
40
11
  * publishSarifReview (private test seam). Running this file directly calls
41
12
  * main with the process and sets process.exitCode.
42
13
  */
43
14
 
44
- const fs = require('node:fs');
45
- const path = require('node:path');
46
-
47
- const { publishSarifReview } = require('../src/index.cjs');
48
-
49
- /** Exit status per public outcome (and for help); every refusal or failure is 1. */
50
- const EXIT = Object.freeze({ help: 0, published: 0, failure: 1, blocked: 2, uncertain: 3, rejected: 1 });
51
-
52
- /** Flags that take exactly one value. */
53
- const VALUE_FLAGS = new Set(['--sarif', '--repo', '--pull', '--commit', '--state', '--source-root', '--old-source-commit']);
54
-
55
- /**
56
- * Decoder for SARIF files, which are UTF-8 JSON (SARIF 2.1.0 §3.1, RFC 8259
57
- * §8.1). `fatal` refuses bytes that are not valid UTF-8 instead of silently
58
- * substituting U+FFFD, which would change what is fingerprinted and
59
- * published. A leading UTF-8 byte-order mark is an encoding signature, not
60
- * JSON content, so it is removed (the decoder's default, `ignoreBOM: false`);
61
- * the library then sees exactly the document a caller would pass in memory.
62
- */
63
- const SARIF_DECODER = new TextDecoder('utf-8', { fatal: true, ignoreBOM: false });
64
-
65
- /** Flags that take no value. */
66
- const BOOLEAN_FLAGS = new Set(['--ignore-approval-hold']);
67
-
68
- /** Flags every publication needs. */
69
- const REQUIRED_FLAGS = ['--sarif', '--repo', '--pull', '--commit', '--state'];
70
-
71
- const md = String.raw;
72
-
73
- const USAGE = md`sarif-to-comment — publish a ready SARIF file as one GitHub draft review
74
-
75
- Usage:
76
- sarif-to-comment --sarif FILE --repo OWNER/REPO --pull N --commit FULLSHA
77
- --state ABSOLUTE_FILE [--source-root ABSOLUTE_FILE_URI]
78
- [--old-source-commit FULLSHA] [--ignore-approval-hold]
79
- sarif-to-comment --help
80
-
81
- Options:
82
- --sarif FILE SARIF 2.1.0 JSON file to publish.
83
- --repo OWNER/REPO Repository of the pull request.
84
- --pull N Pull request number.
85
- --commit FULLSHA Full 40-character commit the review is about.
86
- --state ABSOLUTE_FILE Durable publication state. Retry with the same
87
- file; never delete it after an uncertain
88
- result. A new file starts a separate review.
89
- --source-root ABSOLUTE_FILE_URI
90
- Repository root in the SARIF producer's file
91
- system (file:///.../ ending in "/").
92
- --old-source-commit FULLSHA Candidate commit for the diff's old side, used
93
- only when GitHub's comparison cannot establish
94
- it; verified against the pull request's patches.
95
- --ignore-approval-hold Publish despite an approval hold (bypasses only
96
- the hold, never validation).
97
- --help Show this help. Needs no token, makes no request.
98
-
99
- Credentials:
100
- GH_TOKEN, or else GITHUB_TOKEN: a GitHub personal access token or user token.
101
- GitHub App installation tokens (including the automatic Actions token) are
102
- not supported. There is no token flag.
103
-
104
- Exit status:
105
- 0 published (or already published)
106
- 2 blocked: nothing was published
107
- 3 uncertain: delivery could not be confirmed; retry with the same --state
108
- 1 usage error, unreadable SARIF file, refused request, or operational failure
109
- `;
110
-
111
- /** A command-line mistake the user can fix by changing the arguments. */
112
- class UsageError extends Error {}
113
-
114
- /** Parses argv into { help } or { values, flags } exactly; throws UsageError. */
115
- function parseArgs(argv) {
116
- if (argv.includes('--help') || argv.includes('-h')) return { help: true };
117
- const values = new Map();
118
- const flags = new Set();
119
- for (let i = 0; i < argv.length; i += 1) {
120
- const arg = argv[i];
121
- if (!arg.startsWith('--')) throw new UsageError(`unexpected argument ${arg}`);
122
- const eq = arg.indexOf('=');
123
- const name = eq === -1 ? arg : arg.slice(0, eq);
124
- if (name === '--token') {
125
- throw new UsageError('unknown option --token: the token is read only from GH_TOKEN or GITHUB_TOKEN');
126
- }
127
- if (BOOLEAN_FLAGS.has(name)) {
128
- if (eq !== -1) throw new UsageError(`${name} takes no value`);
129
- if (flags.has(name)) throw new UsageError(`${name} was given more than once`);
130
- flags.add(name);
131
- continue;
132
- }
133
- if (!VALUE_FLAGS.has(name)) throw new UsageError(`unknown option ${name}`);
134
- if (values.has(name)) throw new UsageError(`${name} was given more than once`);
135
- let value;
136
- if (eq !== -1) {
137
- value = arg.slice(eq + 1);
138
- } else {
139
- value = argv[i + 1];
140
- if (value === undefined || value.startsWith('--')) throw new UsageError(`${name} requires a value`);
141
- i += 1;
142
- }
143
- if (value === '') throw new UsageError(`${name} requires a non-empty value`);
144
- values.set(name, value);
145
- }
146
- const missing = REQUIRED_FLAGS.filter((flag) => !values.has(flag));
147
- if (missing.length > 0) throw new UsageError(`missing required option ${missing.join(', ')}`);
148
- return { help: false, values, flags };
149
- }
150
-
151
- /** Converts parsed flags into library input fields; throws UsageError. */
152
- function interpretArgs({ values, flags }) {
153
- const repo = /^([^/\s]+)\/([^/\s]+)$/.exec(values.get('--repo'));
154
- if (!repo) throw new UsageError('--repo must be OWNER/REPO');
155
- const pull = values.get('--pull');
156
- if (!/^[1-9][0-9]*$/.test(pull) || !Number.isSafeInteger(Number(pull))) {
157
- throw new UsageError('--pull must be a positive pull request number');
158
- }
159
- const commitFlag = (flag) => {
160
- const value = values.get(flag);
161
- if (value !== undefined && !/^[0-9a-f]{40}$/.test(value)) {
162
- throw new UsageError(`${flag} must be a full 40-character lowercase commit SHA`);
163
- }
164
- return value;
165
- };
166
- const statePath = values.get('--state');
167
- if (!path.isAbsolute(statePath)) throw new UsageError('--state must be an absolute file path');
168
- const sourceRootUri = values.get('--source-root');
169
- if (sourceRootUri !== undefined && !(sourceRootUri.startsWith('file:') && sourceRootUri.endsWith('/'))) {
170
- throw new UsageError('--source-root must be an absolute file: URI ending in "/"');
171
- }
172
- const input = {
173
- destination: { owner: repo[1], repo: repo[2], pullNumber: Number(pull) },
174
- reviewedCommit: commitFlag('--commit'),
175
- statePath,
176
- };
177
- const oldSourceCommit = commitFlag('--old-source-commit');
178
- if (oldSourceCommit !== undefined) input.oldSourceCommit = oldSourceCommit;
179
- if (sourceRootUri !== undefined) input.sourceRootUri = sourceRootUri;
180
- if (flags.has('--ignore-approval-hold')) input.options = { ignoreApprovalHold: true };
181
- return { sarifPath: values.get('--sarif'), input };
182
- }
183
-
184
- /** The credential from the environment: GH_TOKEN, else GITHUB_TOKEN; empty is unset. */
185
- function tokenFrom(env) {
186
- if (typeof env.GH_TOKEN === 'string' && env.GH_TOKEN !== '') return env.GH_TOKEN;
187
- if (typeof env.GITHUB_TOKEN === 'string' && env.GITHUB_TOKEN !== '') return env.GITHUB_TOKEN;
188
- return undefined;
189
- }
190
-
191
- /** An error's message and cause chain, one line each. */
192
- function describeError(err) {
193
- const lines = [];
194
- const seen = new Set();
195
- for (let current = err; current !== undefined && current !== null && !seen.has(current); current = current.cause) {
196
- seen.add(current);
197
- lines.push(lines.length === 0 ? String(current.message ?? current) : ` caused by: ${current.message ?? current}`);
198
- if (!(current instanceof Error)) break;
199
- }
200
- return lines.join('\n');
201
- }
202
-
203
- /**
204
- * Runs the CLI. Returns the exit status; never throws for expected failures.
205
- */
206
- async function main({ argv, env, stdout, stderr }, internals) {
207
- const token = tokenFrom(env);
208
- const safe = (text) => (token === undefined ? String(text) : String(text).split(token).join('[redacted]'));
209
- const fail = (message) => {
210
- stderr.write(`sarif-to-comment: ${safe(message)}\n`);
211
- return EXIT.failure;
212
- };
213
-
214
- let parsed;
215
- let request;
216
- try {
217
- parsed = parseArgs(argv);
218
- if (parsed.help) {
219
- stdout.write(USAGE);
220
- return EXIT.help;
221
- }
222
- request = interpretArgs(parsed);
223
- } catch (err) {
224
- if (err instanceof UsageError) return fail(`${err.message}\nRun sarif-to-comment --help for usage.`);
225
- throw err;
226
- }
227
- if (token === undefined) {
228
- return fail('no GitHub token: set GH_TOKEN (or GITHUB_TOKEN) to a personal access token or user token.');
229
- }
230
-
231
- let bytes;
232
- try {
233
- bytes = fs.readFileSync(request.sarifPath);
234
- } catch (err) {
235
- return fail(`cannot read SARIF file ${request.sarifPath}: ${err.message}`);
236
- }
237
- let text;
238
- try {
239
- text = SARIF_DECODER.decode(bytes);
240
- } catch {
241
- return fail(
242
- `SARIF file ${request.sarifPath} is not valid UTF-8; nothing was published. SARIF files must be UTF-8 encoded JSON.`,
243
- );
244
- }
245
- let sarif;
246
- try {
247
- sarif = JSON.parse(text);
248
- } catch (err) {
249
- return fail(`SARIF file ${request.sarifPath} is not valid JSON: ${err.message}`);
250
- }
251
-
252
- let outcome;
253
- try {
254
- outcome = await publishSarifReview({ ...request.input, sarif, token }, internals);
255
- } catch (err) {
256
- return fail(describeError(err));
257
- }
258
- const markdown = safe(outcome.markdown);
259
- stdout.write(markdown.endsWith('\n') ? markdown : `${markdown}\n`);
260
- return EXIT[outcome.status] ?? EXIT.failure;
261
- }
15
+ const { main } = require('../src/cli.cjs');
262
16
 
263
17
  if (require.main === module) {
264
18
  main({ argv: process.argv.slice(2), env: process.env, stdout: process.stdout, stderr: process.stderr }).then(
@@ -267,7 +21,7 @@ if (require.main === module) {
267
21
  },
268
22
  (err) => {
269
23
  process.stderr.write(`sarif-to-comment: unexpected failure: ${err && err.message}\n`);
270
- process.exitCode = EXIT.failure;
24
+ process.exitCode = 1;
271
25
  },
272
26
  );
273
27
  }
package/docs/api/index.md CHANGED
@@ -24,7 +24,7 @@ Description
24
24
 
25
25
  </td><td>
26
26
 
27
- Publish a ready SARIF 2.1.0 document as one GitHub draft pull request review.
27
+ Author, inspect and extend SARIF 2.1.0, and publish it as one GitHub draft pull request review.
28
28
 
29
29
 
30
30
  </td></tr>
@@ -0,0 +1,91 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [sarif-to-comment](./sarif-to-comment.md) &gt; [addSarifComment](./sarif-to-comment.addsarifcomment.md)
4
+
5
+ ## addSarifComment() function
6
+
7
+ Adds one finding on a line or line range to a copy of a SARIF document.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ export declare function addSarifComment(sarif: object, comment: ISarifComment): AddSarifCommentOutcome;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ <table><thead><tr><th>
18
+
19
+ Parameter
20
+
21
+
22
+ </th><th>
23
+
24
+ Type
25
+
26
+
27
+ </th><th>
28
+
29
+ Description
30
+
31
+
32
+ </th></tr></thead>
33
+ <tbody><tr><td>
34
+
35
+ sarif
36
+
37
+
38
+ </td><td>
39
+
40
+ object
41
+
42
+
43
+ </td><td>
44
+
45
+ A SARIF log as a parsed JSON object.
46
+
47
+
48
+ </td></tr>
49
+ <tr><td>
50
+
51
+ comment
52
+
53
+
54
+ </td><td>
55
+
56
+ [ISarifComment](./sarif-to-comment.isarifcomment.md)
57
+
58
+
59
+ </td><td>
60
+
61
+ The finding.
62
+
63
+
64
+ </td></tr>
65
+ </tbody></table>
66
+
67
+ **Returns:**
68
+
69
+ [AddSarifCommentOutcome](./sarif-to-comment.addsarifcommentoutcome.md)
70
+
71
+ `added` with the new document, or `invalid` if the input is not schema-valid SARIF or has no run.
72
+
73
+ ## Exceptions
74
+
75
+ `TypeError` for a malformed comment, a run index out of range, or a document with several runs and no `run` choice.
76
+
77
+ ## Remarks
78
+
79
+ Works on any schema-valid SARIF, whether it came from[createSarifDocument()](./sarif-to-comment.createsarifdocument.md) or from another producer. The input is copied and never changed; every existing run, finding and property is kept. Only what you supply is written: no source is read, so lines are checked later, by [addStagedChangesToSarif()](./sarif-to-comment.addstagedchangestosarif.md) and by publication.
80
+
81
+ ## Example
82
+
83
+
84
+ ```ts
85
+ import { createSarifDocument, addSarifComment } from 'sarif-to-comment';
86
+
87
+ let sarif = createSarifDocument({ tool: { name: 'Review agent' } });
88
+ const added = addSarifComment(sarif, { file: 'src/parse.js', line: 2, message: 'Handle empty input.' });
89
+ if (added.status === 'added') sarif = added.sarif;
90
+ ```
91
+
@@ -0,0 +1,15 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [sarif-to-comment](./sarif-to-comment.md) &gt; [AddSarifCommentOutcome](./sarif-to-comment.addsarifcommentoutcome.md)
4
+
5
+ ## AddSarifCommentOutcome type
6
+
7
+ Every outcome of [addSarifComment()](./sarif-to-comment.addsarifcomment.md)<!-- -->, discriminated by `status`<!-- -->.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ export type AddSarifCommentOutcome = IAddedSarifCommentOutcome | IInvalidSarifOutcome;
13
+ ```
14
+ **References:** [IAddedSarifCommentOutcome](./sarif-to-comment.iaddedsarifcommentoutcome.md)<!-- -->, [IInvalidSarifOutcome](./sarif-to-comment.iinvalidsarifoutcome.md)
15
+
@@ -0,0 +1,15 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [sarif-to-comment](./sarif-to-comment.md) &gt; [AddStagedChangesOutcome](./sarif-to-comment.addstagedchangesoutcome.md)
4
+
5
+ ## AddStagedChangesOutcome type
6
+
7
+ Every outcome of [addStagedChangesToSarif()](./sarif-to-comment.addstagedchangestosarif.md)<!-- -->, discriminated by `status`<!-- -->.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ export type AddStagedChangesOutcome = IAddedStagedChangesOutcome | IInvalidSarifOutcome | IFailedStagedChangesOutcome;
13
+ ```
14
+ **References:** [IAddedStagedChangesOutcome](./sarif-to-comment.iaddedstagedchangesoutcome.md)<!-- -->, [IInvalidSarifOutcome](./sarif-to-comment.iinvalidsarifoutcome.md)<!-- -->, [IFailedStagedChangesOutcome](./sarif-to-comment.ifailedstagedchangesoutcome.md)
15
+
@@ -0,0 +1,66 @@
1
+ <!-- Do not edit this file. It is automatically generated by API Documenter. -->
2
+
3
+ [Home](./index.md) &gt; [sarif-to-comment](./sarif-to-comment.md) &gt; [addStagedChangesToSarif](./sarif-to-comment.addstagedchangestosarif.md)
4
+
5
+ ## addStagedChangesToSarif() function
6
+
7
+ Adds the changes staged in a Git index, relative to a reviewed commit, to a copy of a SARIF document as fixes on the findings they belong to.
8
+
9
+ **Signature:**
10
+
11
+ ```typescript
12
+ export declare function addStagedChangesToSarif(input: IAddStagedChangesInput): Promise<AddStagedChangesOutcome>;
13
+ ```
14
+
15
+ ## Parameters
16
+
17
+ <table><thead><tr><th>
18
+
19
+ Parameter
20
+
21
+
22
+ </th><th>
23
+
24
+ Type
25
+
26
+
27
+ </th><th>
28
+
29
+ Description
30
+
31
+
32
+ </th></tr></thead>
33
+ <tbody><tr><td>
34
+
35
+ input
36
+
37
+
38
+ </td><td>
39
+
40
+ [IAddStagedChangesInput](./sarif-to-comment.iaddstagedchangesinput.md)
41
+
42
+
43
+ </td><td>
44
+
45
+ The document, worktree, reviewed commit and repository.
46
+
47
+
48
+ </td></tr>
49
+ </tbody></table>
50
+
51
+ **Returns:**
52
+
53
+ Promise&lt;[AddStagedChangesOutcome](./sarif-to-comment.addstagedchangesoutcome.md)<!-- -->&gt;
54
+
55
+ `added` with the new document and a receipt, `invalid` for input that is not schema-valid SARIF, or `failed`<!-- -->.
56
+
57
+ ## Exceptions
58
+
59
+ `TypeError` for malformed input; an `Error` when Git cannot be run, the worktree is not in a repository, or the reviewed commit is not available locally.
60
+
61
+ ## Remarks
62
+
63
+ Reads one snapshot of the index and the reviewed commit by blob identity; working-tree files, filters and hooks are never used, and nothing in the repository is changed. Applying the resulting replacements to the reviewed files reproduces the staged files exactly.
64
+
65
+ A finding receives a change only when its lines lie within the change's reviewed lines; neither is enlarged. Findings with their own fixes are never changed. A change no finding explains is added as a factual result in a new run attributed to this package. File creation and deletion become proposed file operations, which inspection shows but the current publisher refuses. Unsupported changes fail the whole call rather than being dropped.
66
+