opencode-github-release 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 (2) hide show
  1. package/dist/index.js +53 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -21,11 +21,62 @@ function bumpVersion(current, bump) {
21
21
  }
22
22
  return `v${major}.${minor}.${patch}`;
23
23
  }
24
+ function classifyCommit(subject) {
25
+ const breaking = /^BREAKING CHANGE:/im.test(subject) || /^\w+(\([^)]*\))?!:/m.test(subject);
26
+ const match = subject.match(/^(\w+)(\([^)]*\))?(!)?\s*:/);
27
+ const type = match?.[1]?.toLowerCase();
28
+ if (type === "feat") return { type: "feat", breaking };
29
+ if (type === "fix") return { type: "fix", breaking };
30
+ return { type: "other", breaking };
31
+ }
24
32
  var plugin = async ({ $ }) => {
25
33
  return {
26
34
  tool: {
35
+ suggest_bump: tool({
36
+ description: "Analyze git history since the latest tag and suggest a semantic version bump. Call this tool when the user asks to create a release but does NOT specify patch/minor/major or an explicit version string. After receiving the suggestion, present it to the user and ask for confirmation before calling create_release.",
37
+ args: {},
38
+ async execute(_args, _context) {
39
+ await $`git fetch --tags --force 2>/dev/null || true`;
40
+ const tagResult = await $`git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0"`;
41
+ const latestTag = tagResult.stdout.toString().trim();
42
+ const logResult = await $`git log ${latestTag}..HEAD --oneline 2>/dev/null || true`;
43
+ const logText = logResult.stdout.toString().trim();
44
+ if (!logText) {
45
+ return `No new commits since ${latestTag}. No release needed.`;
46
+ }
47
+ const lines = logText.split("\n");
48
+ const entries = lines.map((line) => {
49
+ const hash = line.split(/\s+/)[0];
50
+ const subject = line.slice(hash.length).trim();
51
+ const { type, breaking } = classifyCommit(subject);
52
+ return { hash, subject, type, breaking };
53
+ });
54
+ let suggestedBump = "patch";
55
+ for (const entry of entries) {
56
+ if (entry.breaking) {
57
+ suggestedBump = "major";
58
+ break;
59
+ }
60
+ if (entry.type === "feat") {
61
+ suggestedBump = "minor";
62
+ }
63
+ }
64
+ const output = entries.map((e) => {
65
+ const tag = e.breaking ? "[BREAKING]" : e.type === "feat" ? "[feat]" : e.type === "fix" ? "[fix]" : " ";
66
+ return ` ${tag} ${e.hash} ${e.subject}`;
67
+ }).join("\n");
68
+ return [
69
+ `Latest tag: ${latestTag}`,
70
+ `Commits: ${entries.length}`,
71
+ "",
72
+ output,
73
+ "",
74
+ `Suggested bump: ${suggestedBump} -> ${bumpVersion(latestTag, suggestedBump)}`
75
+ ].join("\n");
76
+ }
77
+ }),
27
78
  create_release: tool({
28
- description: 'Create a git tag and publish a GitHub release with semantic versioning. Provide either `bump` to auto-compute the next version from the latest tag, or an explicit `version` string (e.g. "2.0.0" or "v2.0.0").',
79
+ description: 'Create a git tag and publish a GitHub release with semantic versioning. Provide either `bump` to auto-compute the next version from the latest tag, or an explicit `version` string (e.g. "2.0.0" or "v2.0.0"). If the user only asks to "create a release" without specifying a bump or version, call suggest_bump first instead of this tool.',
29
80
  args: {
30
81
  bump: tool.schema.enum(["patch", "minor", "major"]).optional(),
31
82
  version: tool.schema.string().optional(),
@@ -48,7 +99,7 @@ var plugin = async ({ $ }) => {
48
99
  } else {
49
100
  await $`gh release create ${newTag} --title ${newTag} --generate-notes`;
50
101
  }
51
- return `\u2713 Created and published ${newTag} (bumped from ${latestTag})`;
102
+ return `Created and published ${newTag} (bumped from ${latestTag})`;
52
103
  }
53
104
  })
54
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-github-release",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "OpenCode plugin to create git tags and publish GitHub releases with semantic versioning.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",