abapgit-agent 1.4.0 → 1.5.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.
@@ -0,0 +1,277 @@
1
+ /**
2
+ * Unrelease script - Remove a release
3
+ *
4
+ * Usage: npm run unrelease [version] [--dry-run]
5
+ *
6
+ * Options:
7
+ * --dry-run Test the unrelease flow without making actual changes
8
+ *
9
+ * This script:
10
+ * 1. Takes a version as argument (default: current version from package.json)
11
+ * 2. Deletes the GitHub release
12
+ * 3. Deletes the git tag
13
+ * 4. Removes release notes from RELEASE_NOTES.md
14
+ * 5. Restores version in local files (or shows what would be restored in dry-run)
15
+ * 6. Removes release commits from git history (top 2 commits if they match release pattern)
16
+ */
17
+
18
+ const fs = require('fs');
19
+ const path = require('path');
20
+ const { execSync } = require('child_process');
21
+
22
+ const packageJsonPath = path.join(__dirname, '..', 'package.json');
23
+ const releaseNotesPath = path.join(__dirname, '..', 'RELEASE_NOTES.md');
24
+ const repoRoot = path.join(__dirname, '..');
25
+
26
+ // Get version from argument or package.json
27
+ let version = process.argv[2];
28
+
29
+ // Check for --dry-run flag
30
+ const args = process.argv.slice(2);
31
+ const dryRun = args.includes('--dry-run');
32
+
33
+ // Remove version and dry-run from args to get clean list
34
+ const remainingArgs = args.filter(arg => arg !== '--dry-run' && !arg.startsWith('--'));
35
+ if (!version && remainingArgs.length > 0) {
36
+ version = remainingArgs[0];
37
+ }
38
+
39
+ if (!version) {
40
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
41
+ version = pkg.version;
42
+ }
43
+
44
+ // Ensure version has 'v' prefix for tag
45
+ const versionTag = version.startsWith('v') ? version : `v${version}`;
46
+ const versionNoV = version.startsWith('v') ? version.slice(1) : version;
47
+
48
+ if (dryRun) {
49
+ console.log('🔹 DRY RUN MODE - No actual changes will be made\n');
50
+ }
51
+
52
+ console.log(`Unreleasing version: ${versionNoV} (tag: ${versionTag})`);
53
+ console.log('');
54
+
55
+ // Check if there's a remote for github.com
56
+ let remoteName = 'origin';
57
+ try {
58
+ const remotes = execSync('git remote -v', { cwd: repoRoot, encoding: 'utf8' });
59
+ if (remotes.includes('public') && remotes.includes('github.com')) {
60
+ remoteName = 'public';
61
+ }
62
+ console.log(`Using remote: ${remoteName}`);
63
+ } catch (e) {
64
+ console.log('Could not determine remote, using origin');
65
+ }
66
+
67
+ console.log('');
68
+
69
+ // Step 1: Delete GitHub release
70
+ if (dryRun) {
71
+ console.log(`🔹 DRY RUN - Would delete GitHub release: ${versionTag}`);
72
+ } else {
73
+ console.log('Deleting GitHub release...');
74
+ try {
75
+ execSync(`gh release delete ${versionTag} --repo SylvosCai/abapgit-agent --yes`, { cwd: repoRoot, encoding: 'utf8' });
76
+ console.log('✅ GitHub release deleted');
77
+ } catch (e) {
78
+ console.log('⚠️ GitHub release not found or already deleted');
79
+ }
80
+ }
81
+ console.log('');
82
+
83
+ // Step 2: Delete git tag locally and remotely
84
+ if (dryRun) {
85
+ console.log(`🔹 DRY RUN - Would delete git tag: ${versionTag}`);
86
+ } else {
87
+ console.log('Deleting git tag...');
88
+ try {
89
+ execSync(`git tag -d ${versionTag}`, { cwd: repoRoot, encoding: 'utf8' });
90
+ console.log('✅ Local tag deleted');
91
+ } catch (e) {
92
+ console.log('⚠️ Local tag not found');
93
+ }
94
+
95
+ try {
96
+ execSync(`git push ${remoteName} --delete ${versionTag}`, { cwd: repoRoot, encoding: 'utf8' });
97
+ console.log('✅ Remote tag deleted');
98
+ } catch (e) {
99
+ console.log('⚠️ Remote tag not found or already deleted');
100
+ }
101
+ }
102
+ console.log('');
103
+
104
+ // Step 3: Remove release notes from RELEASE_NOTES.md
105
+ if (dryRun) {
106
+ console.log(`🔹 DRY RUN - Would remove release notes for v${versionNoV} from RELEASE_NOTES.md`);
107
+ } else {
108
+ console.log('Removing release notes from RELEASE_NOTES.md...');
109
+ if (fs.existsSync(releaseNotesPath)) {
110
+ let content = fs.readFileSync(releaseNotesPath, 'utf8');
111
+
112
+ // Check if version exists in release notes
113
+ const versionHeader = `## v${versionNoV}`;
114
+ if (content.includes(versionHeader)) {
115
+ // Remove the version section (from ## vX.X.X to next --- or end)
116
+ const lines = content.split('\n');
117
+ const newLines = [];
118
+ let inVersionSection = false;
119
+ let foundVersion = false;
120
+
121
+ for (let i = 0; i < lines.length; i++) {
122
+ const line = lines[i];
123
+
124
+ // Match exactly the version header (e.g., ## v1.4.1)
125
+ if (line.trim() === versionHeader) {
126
+ inVersionSection = true;
127
+ foundVersion = true;
128
+ continue;
129
+ }
130
+
131
+ if (inVersionSection) {
132
+ // Stop at next --- separator or exact version header
133
+ if (line.startsWith('---')) {
134
+ inVersionSection = false;
135
+ newLines.push(line);
136
+ } else if (line.trim().startsWith('## v')) {
137
+ // Check if it's another exact version header (e.g., ## v1.4.0)
138
+ const trimmed = line.trim();
139
+ if (trimmed.match(/^## v\d+\.\d+\.\d+$/)) {
140
+ inVersionSection = false;
141
+ newLines.push(line);
142
+ }
143
+ }
144
+ // Otherwise skip this line (part of the version section)
145
+ } else {
146
+ newLines.push(line);
147
+ }
148
+ }
149
+
150
+ if (foundVersion) {
151
+ fs.writeFileSync(releaseNotesPath, newLines.join('\n').trim() + '\n');
152
+ console.log('✅ Release notes removed');
153
+ } else {
154
+ console.log('⚠️ Version not found in RELEASE_NOTES.md');
155
+ }
156
+ } else {
157
+ console.log('⚠️ Version not found in RELEASE_NOTES.md');
158
+ }
159
+ } else {
160
+ console.log('⚠️ RELEASE_NOTES.md not found');
161
+ }
162
+ }
163
+ console.log('');
164
+
165
+ // Step 4: Restore version in package.json and abap health resource
166
+ console.log('Restoring version in local files...');
167
+
168
+ // Restore package.json to previous version (find previous tag)
169
+ const allTags = execSync('git tag --sort=-v:refname', { cwd: repoRoot, encoding: 'utf8' });
170
+ const tagList = allTags.trim().split('\n').filter(t => t.startsWith('v') && t !== versionTag);
171
+ const previousTag = tagList[0];
172
+
173
+ if (previousTag) {
174
+ // In dry-run mode, still restore files but don't commit
175
+ if (dryRun) {
176
+ try {
177
+ execSync(`git show ${previousTag}:package.json > ${packageJsonPath}`, { cwd: repoRoot, encoding: 'utf8' });
178
+ console.log(`🔹 DRY RUN - Restored package.json from ${previousTag}`);
179
+ } catch (e) {
180
+ console.log('⚠️ Could not restore package.json');
181
+ }
182
+
183
+ try {
184
+ execSync(`git show ${previousTag}:abap/zcl_abgagt_resource_health.clas.abap > abap/zcl_abgagt_resource_health.clas.abap`, { cwd: repoRoot, encoding: 'utf8' });
185
+ console.log(`🔹 DRY RUN - Restored ABAP health resource from ${previousTag}`);
186
+ } catch (e) {
187
+ console.log('⚠️ Could not restore ABAP health resource');
188
+ }
189
+ } else {
190
+ try {
191
+ execSync(`git show ${previousTag}:package.json > ${packageJsonPath}`, { cwd: repoRoot, encoding: 'utf8' });
192
+ console.log('✅ package.json restored to previous version');
193
+ } catch (e) {
194
+ console.log('⚠️ Could not restore package.json');
195
+ }
196
+
197
+ try {
198
+ execSync(`git show ${previousTag}:abap/zcl_abgagt_resource_health.clas.abap > abap/zcl_abgagt_resource_health.clas.abap`, { cwd: repoRoot, encoding: 'utf8' });
199
+ console.log('✅ ABAP health resource restored to previous version');
200
+ } catch (e) {
201
+ console.log('⚠️ Could not restore ABAP health resource');
202
+ }
203
+ }
204
+ } else {
205
+ console.log('⚠️ No previous tag found, cannot restore version');
206
+ }
207
+ console.log('');
208
+
209
+ // Step 5: Remove release commits from remote if they exist
210
+ // Pattern: "chore: release vX.X.X" followed by "X.X.X"
211
+ console.log('Checking for release commits on remote...');
212
+ try {
213
+ // Get top 2 commit messages from remote
214
+ let remoteRef;
215
+ try {
216
+ remoteRef = execSync(`git rev-parse ${remoteName}/master 2>/dev/null`, { cwd: repoRoot, encoding: 'utf8' }).trim();
217
+ } catch (e) {
218
+ try {
219
+ remoteRef = execSync(`git rev-parse ${remoteName}/main 2>/dev/null`, { cwd: repoRoot, encoding: 'utf8' }).trim();
220
+ } catch (e2) {
221
+ remoteRef = '';
222
+ }
223
+ }
224
+
225
+ if (!remoteRef) {
226
+ console.log('⚠️ Could not determine remote ref');
227
+ } else {
228
+ // Get top 2 commits from remote
229
+ const remoteTopCommits = execSync(`git log ${remoteRef} -2 --format="%s"`, { cwd: repoRoot, encoding: 'utf8' }).trim().split('\n');
230
+
231
+ if (remoteTopCommits.length >= 2) {
232
+ const firstCommit = remoteTopCommits[0]; // Most recent on remote
233
+ const secondCommit = remoteTopCommits[1]; // Second most recent on remote
234
+
235
+ // Check if they match the expected pattern
236
+ // firstCommit (HEAD) = "chore: release vX.X.X"
237
+ // secondCommit (HEAD~1) = "X.X.X" (just version number)
238
+ const isReleaseCommit = firstCommit && firstCommit.match(/^chore: release v\d+\.\d+\.\d+$/);
239
+ const isVersionBump = secondCommit && secondCommit.match(/^\d+\.\d+\.\d+$/);
240
+
241
+ if (isReleaseCommit && isVersionBump) {
242
+ // Found release commits on remote - need to force push to remove them
243
+ // Find the commit to reset to (before the version bump)
244
+ const resetToRef = execSync(`git rev-parse ${remoteRef}~2`, { cwd: repoRoot, encoding: 'utf8' }).trim();
245
+
246
+ if (dryRun) {
247
+ console.log(`🔹 DRY RUN - Would force push to remove release commits from remote`);
248
+ console.log(` Would remove: "${firstCommit}" and "${secondCommit}"`);
249
+ console.log(` Would reset remote to: ${resetToRef.slice(0, 7)}`);
250
+ } else {
251
+ // Reset to the commit before release, then force push
252
+ execSync(`git reset --hard ${resetToRef}`, { cwd: repoRoot });
253
+ console.log('✅ Reset to commit before release');
254
+
255
+ // Force push to remove from remote
256
+ console.log('Force pushing to remote...');
257
+ execSync(`git push ${remoteName} +HEAD --force`, { cwd: repoRoot });
258
+ console.log('✅ Force pushed to remote - release commits removed from history');
259
+ }
260
+ } else {
261
+ console.log('⚠️ Remote top commits do not match release pattern, skipping');
262
+ console.log(` Found: "${firstCommit}" and "${secondCommit}"`);
263
+ }
264
+ } else {
265
+ console.log('⚠️ Not enough commits on remote to check');
266
+ }
267
+ }
268
+ } catch (e) {
269
+ console.log('⚠️ Could not check/remove release commits:', e.message);
270
+ }
271
+ console.log('');
272
+
273
+ if (dryRun) {
274
+ console.log('🔹 DRY RUN COMPLETE - No actual changes made');
275
+ } else {
276
+ console.log('Done!');
277
+ }
package/src/agent.js CHANGED
@@ -53,7 +53,7 @@ class ABAPGitAgent {
53
53
  return {
54
54
  status: 'healthy',
55
55
  abap: 'connected',
56
- version: result.version || '1.0.0'
56
+ version: result.version || '1.4.0'
57
57
  };
58
58
  } catch (error) {
59
59
  return {
package/src/config.js CHANGED
@@ -33,7 +33,8 @@ function loadConfig() {
33
33
  password: process.env.ABAP_PASSWORD,
34
34
  language: process.env.ABAP_LANGUAGE || 'EN',
35
35
  gitUsername: process.env.GIT_USERNAME,
36
- gitPassword: process.env.GIT_PASSWORD
36
+ gitPassword: process.env.GIT_PASSWORD,
37
+ transport: process.env.ABAP_TRANSPORT
37
38
  };
38
39
  }
39
40
 
@@ -59,8 +60,14 @@ function getAgentConfig() {
59
60
  return cfg.agent;
60
61
  }
61
62
 
63
+ function getTransport() {
64
+ const cfg = loadConfig();
65
+ return cfg.transport;
66
+ }
67
+
62
68
  module.exports = {
63
69
  loadConfig,
64
70
  getAbapConfig,
65
- getAgentConfig
71
+ getAgentConfig,
72
+ getTransport
66
73
  };