@eduardo191labs/opencode-actions 0.1.2 → 0.1.3
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 +192 -5
- package/action.yml +18 -0
- package/dist/actions.d.ts +266 -68
- package/dist/actions.js +134 -24
- package/dist/app-auth.d.ts +70 -0
- package/dist/app-auth.js +137 -0
- package/dist/cli.js +34 -3
- package/dist/commands.d.ts +3 -1
- package/dist/commands.js +59 -19
- package/dist/config.d.ts +5 -1
- package/dist/config.js +1 -1
- package/dist/detect.d.ts +37 -4
- package/dist/detect.js +101 -138
- package/dist/format.d.ts +3 -1
- package/dist/format.js +5 -2
- package/dist/git.d.ts +16 -0
- package/dist/git.js +23 -1
- package/dist/github.d.ts +9 -1
- package/dist/implement.d.ts +116 -0
- package/dist/implement.js +192 -0
- package/dist/install.js +195 -20
- package/dist/signals.d.ts +134 -0
- package/dist/signals.js +117 -0
- package/dist/summary.js +2 -0
- package/package.json +1 -1
package/dist/signals.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The small signals that make a bot feel present: a reaction while it works, an
|
|
3
|
+
* emoji when it is done, and an issue closed when its pull request merges.
|
|
4
|
+
*
|
|
5
|
+
* GitHub Copilot never leaves an author guessing whether a request was heard. A
|
|
6
|
+
* run takes minutes, and without an acknowledgement the comment looks ignored.
|
|
7
|
+
* The reaction is the acknowledgement, and the emoji at the end is the receipt.
|
|
8
|
+
*/
|
|
9
|
+
/** What the bot reacts with, in order of meaning. */
|
|
10
|
+
export const REACTIONS = {
|
|
11
|
+
/** Accepted: the request was understood and is running. */
|
|
12
|
+
accepted: "eyes",
|
|
13
|
+
/** Finished, with a change. */
|
|
14
|
+
done: "+1",
|
|
15
|
+
/** Finished, nothing to do or the request was refused. */
|
|
16
|
+
nothing: "-1",
|
|
17
|
+
/** Failed. */
|
|
18
|
+
failed: "confused",
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* React to a comment or issue.
|
|
22
|
+
*
|
|
23
|
+
* GitHub accepts a fixed set of reaction names; anything else is a 422, which is
|
|
24
|
+
* why the set is enumerated rather than free text. A failure is swallowed: a
|
|
25
|
+
* missing reaction must never fail the work the reaction was acknowledging.
|
|
26
|
+
*/
|
|
27
|
+
export async function react(github, repo, subject, reaction) {
|
|
28
|
+
const path = subject.kind === "comment"
|
|
29
|
+
? `/repos/${repo.owner}/${repo.repo}/issues/comments/${subject.commentId}/reactions`
|
|
30
|
+
: `/repos/${repo.owner}/${repo.repo}/issues/${subject.number}/reactions`;
|
|
31
|
+
return github.post(path, { content: reaction }).catch(() => null);
|
|
32
|
+
}
|
|
33
|
+
/** Pull requests and issues share the same issue-number space. */
|
|
34
|
+
export function subjectFor(input) {
|
|
35
|
+
if (input.commentId)
|
|
36
|
+
return { kind: "comment", number: input.number, commentId: input.commentId };
|
|
37
|
+
return { kind: input.isPull ? "pull" : "issue", number: input.number };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Close the issue a pull request belongs to, when the pull request closes it.
|
|
41
|
+
*
|
|
42
|
+
* GitHub does this itself for `Closes #n` in a merged PR body, but only for the
|
|
43
|
+
* default branch and only when the body was written correctly. Doing it
|
|
44
|
+
* explicitly covers the cases GitHub skips: a bot-written body, a merge into a
|
|
45
|
+
* release branch, and a PR whose body a person edited.
|
|
46
|
+
*/
|
|
47
|
+
export async function closeLinkedIssues(github, repo, pull) {
|
|
48
|
+
const numbers = new Set();
|
|
49
|
+
const text = `${pull.title ?? ""}\n${pull.body ?? ""}`;
|
|
50
|
+
for (const match of text.matchAll(/\b(?:closes|fixes|resolves|refs)\s+#(\d+)/gi)) {
|
|
51
|
+
numbers.add(Number(match[1]));
|
|
52
|
+
}
|
|
53
|
+
for (const match of text.matchAll(/\/issues\/(\d+)/g))
|
|
54
|
+
numbers.add(Number(match[1]));
|
|
55
|
+
if (!numbers.size)
|
|
56
|
+
return { closed: [] };
|
|
57
|
+
const closed = [];
|
|
58
|
+
for (const number of numbers) {
|
|
59
|
+
const issue = await github.getIssue(repo, number).catch(() => null);
|
|
60
|
+
// Never close a pull request by mistake: they share the number space.
|
|
61
|
+
if (!issue || issue.pull_request || issue.state === "closed")
|
|
62
|
+
continue;
|
|
63
|
+
await github.updateIssue(repo, number, {
|
|
64
|
+
state: "closed",
|
|
65
|
+
state_reason: "completed",
|
|
66
|
+
});
|
|
67
|
+
await github
|
|
68
|
+
.comment(repo, number, `Closed by #${pull.number}, which is merged.`)
|
|
69
|
+
.catch(() => { });
|
|
70
|
+
closed.push(number);
|
|
71
|
+
}
|
|
72
|
+
return { closed };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Announce a merge inside the pull request, so the thread ends with a result
|
|
76
|
+
* rather than a merge commit nobody reads.
|
|
77
|
+
*/
|
|
78
|
+
export async function commentMerge(github, repo, pullNumber, detail) {
|
|
79
|
+
const issues = detail.issues.length ? `\n\nCloses ${detail.issues.map((n) => `#${n}`).join(", ")}.` : "";
|
|
80
|
+
const body = `Merged${detail.method ? ` with ${detail.method}` : ""}${detail.sha ? ` as ${detail.sha.slice(0, 7)}` : ""}.${issues}`;
|
|
81
|
+
return github.comment(repo, pullNumber, body).catch(() => null);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Merge, and when GitHub refuses because the branch is behind or conflicting,
|
|
85
|
+
* say exactly which, because "merge failed" tells the author nothing.
|
|
86
|
+
*
|
|
87
|
+
* A conflict is not something a merge call can resolve: the branch has to be
|
|
88
|
+
* updated and the conflict committed. Returning the reason lets the caller run
|
|
89
|
+
* that step instead of retrying the same merge.
|
|
90
|
+
*/
|
|
91
|
+
export async function mergeWithReason(github, repo, pullNumber, method = "squash") {
|
|
92
|
+
const pull = await github.getPull(repo, pullNumber);
|
|
93
|
+
if (pull.merged)
|
|
94
|
+
return { merged: true, already: true, sha: pull.merge_commit_sha ?? undefined };
|
|
95
|
+
const mergeable = pull.mergeable;
|
|
96
|
+
const state = pull.mergeable_state;
|
|
97
|
+
if (mergeable === false || state === "dirty") {
|
|
98
|
+
return { merged: false, conflict: true, reason: "the branch has conflicts with its base" };
|
|
99
|
+
}
|
|
100
|
+
if (state === "behind") {
|
|
101
|
+
return { merged: false, behind: true, reason: "the branch is behind its base and needs an update" };
|
|
102
|
+
}
|
|
103
|
+
if (state === "blocked") {
|
|
104
|
+
return { merged: false, blocked: true, reason: "a required check or review has not passed" };
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
const result = await github.mergePull(repo, pullNumber, {
|
|
108
|
+
merge_method: method,
|
|
109
|
+
commit_title: `${pull.title} (#${pullNumber})`,
|
|
110
|
+
});
|
|
111
|
+
return { merged: Boolean(result?.merged), sha: result?.sha, method };
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
// A 405 carries GitHub's own explanation, usually the conflict or the check.
|
|
115
|
+
return { merged: false, reason: error?.body?.split("\n")[0] ?? error?.message ?? "merge refused" };
|
|
116
|
+
}
|
|
117
|
+
}
|
package/dist/summary.js
CHANGED
|
@@ -39,6 +39,8 @@ else if (result.rejected) {
|
|
|
39
39
|
else if (result.review) {
|
|
40
40
|
const review = result.review;
|
|
41
41
|
const findings = review.findings ?? [];
|
|
42
|
+
// `posted` is the verdict, not the GitHub review state: every review is sent as
|
|
43
|
+
// COMMENT, so the icon must not imply a block that does not exist.
|
|
42
44
|
const icon = result.posted === "APPROVE" ? "✅" : result.posted === "REQUEST_CHANGES" ? "🚧" : "💬";
|
|
43
45
|
lines.push(`${icon} **${result.posted ?? "COMMENT"}**`, "");
|
|
44
46
|
lines.push(review.summary ?? "", "");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@eduardo191labs/opencode-actions",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"description": "GitHub Copilot-equivalent bot for OpenCode: PRs, reviews, issues, workflow autofix, MCP tools and comment commands.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"license": "MIT",
|