@docupace/pipeline 1.0.7-7.micro-cli12 → 1.0.7-alpha.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.
- package/.prettierrc.cjs +12 -12
- package/bin/next-changeset-validate.sh +8 -8
- package/eslint.config.js +26 -49
- package/next/changeset.sh +75 -75
- package/next/copy.sh +34 -34
- package/next/deploy.sh +40 -40
- package/next/execute.sh +117 -123
- package/next/sonar.sh +23 -23
- package/package.json +7 -23
- package/src/changeset/cli.js +281 -237
- package/src/changeset/validate.js +47 -91
- package/src/jenkins/setParams.groovy +59 -58
- package/src/next/cli.js +15 -111
- package/src/next/config.js +72 -137
- package/src/next/copy.js +30 -61
- package/src/next/deploy.js +314 -633
- package/src/next/jenkins.js +88 -123
- package/src/next/pipline.js +115 -114
- package/src/next/publish.js +48 -71
- package/src/next/pull.js +7 -7
- package/src/next/sonar.js +23 -23
- package/README.md +0 -136
- package/bin/azuread_update_callbacks_for_app.sh +0 -58
- package/bitbucket-pipelines.yml +0 -60
- package/jest.config.js +0 -15
- package/src/auth0/alias.js +0 -79
- package/src/auth0/alias.test.js +0 -172
- package/src/auth0/cli.js +0 -82
- package/src/auth0/configure.js +0 -902
- package/src/auth0/configure.test.js +0 -167
- package/src/auth0/export.js +0 -48
- package/src/auth0/export.test.js +0 -103
- package/src/auth0/metadata.js +0 -141
- package/src/auth0/metadata.test.js +0 -186
- package/src/auth0/vault.js +0 -60
- package/src/auth0/vault.test.js +0 -134
- package/src/changeset/changelog-wiki.js +0 -328
- package/src/changeset/changeset-config.js +0 -34
- package/src/changeset/create.js +0 -215
- package/src/changeset/package-util.js +0 -87
- package/src/changeset/util.js +0 -43
- package/src/changeset/version.js +0 -102
- package/src/lib/merge-driver.js +0 -204
- package/src/merge/cli-merge-all.js +0 -507
- package/src/merge/cli-merge.js +0 -492
- package/src/merge/cli-resolve.js +0 -399
- package/src/merge/cli.js +0 -38
- package/src/merge/merge-changelog.js +0 -87
- package/src/merge/merge-package.js +0 -106
- package/src/merge/merge-types.js +0 -82
- package/src/merge/pr.js +0 -231
- package/src/micro/cli.js +0 -51
- package/src/micro/ms-deploy.js +0 -451
- package/src/micro/ms-publish.js +0 -186
- package/src/next/alias.js +0 -53
- package/src/next/apache.js +0 -81
- package/src/next/connect.js +0 -226
- package/src/next/git-to-semver.js +0 -79
- package/src/next/haproxy.js +0 -76
- package/src/next/jira.js +0 -84
- package/src/next/logger.js +0 -17
- package/src/next/test.js +0 -5
- package/src/next/util.js +0 -93
- package/src/next/vault.js +0 -45
- package/terraform/apply.sh +0 -37
- package/terraform/init.sh +0 -72
- package/terraform/plan.sh +0 -76
- package/terraform/validate.sh +0 -17
package/src/changeset/create.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import OpenAI from 'openai';
|
|
2
|
-
import z from 'zod';
|
|
3
|
-
import { zodResponseFormat } from 'openai/helpers/zod';
|
|
4
|
-
import fs from 'fs';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import inquirer from 'inquirer';
|
|
7
|
-
import { getMainPackage, getPackage, findJiraTicketId } from './util.js';
|
|
8
|
-
import { getPackageNames } from './package-util.js';
|
|
9
|
-
import { execSync } from 'child_process';
|
|
10
|
-
|
|
11
|
-
async function createChangesetDirectory() {
|
|
12
|
-
try {
|
|
13
|
-
// Use path.join to build a safe path to `.changeset`
|
|
14
|
-
const targetDir = path.join(process.cwd(), '.changeset');
|
|
15
|
-
|
|
16
|
-
// Create the directory recursively if it doesn't exist
|
|
17
|
-
await fs.promises.mkdir(targetDir, { recursive: true });
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.error('Error creating .changeset directory:', error);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Gets the current git branch name
|
|
25
|
-
*/
|
|
26
|
-
async function getCurrentBranch() {
|
|
27
|
-
try {
|
|
28
|
-
const branchName = execSync('git branch --show-current', {
|
|
29
|
-
encoding: 'utf8',
|
|
30
|
-
shell: true,
|
|
31
|
-
}).trim();
|
|
32
|
-
console.log(`Current branch: ${branchName}`);
|
|
33
|
-
return branchName;
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error('Error getting current branch:', error.message);
|
|
36
|
-
throw error;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Extracts a Jira ticket ID from a branch name
|
|
41
|
-
*/
|
|
42
|
-
function extractJiraTicketId(branchName) {
|
|
43
|
-
const jiraTicketId = findJiraTicketId(branchName);
|
|
44
|
-
if (!jiraTicketId) {
|
|
45
|
-
throw new Error('No Jira ticket found in the branch name.');
|
|
46
|
-
}
|
|
47
|
-
return jiraTicketId;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Fetches Jira ticket data from Jira API
|
|
52
|
-
*/
|
|
53
|
-
async function fetchJiraTicketData(jiraTicketId) {
|
|
54
|
-
const jiraBaseUrl = 'https://docupacellc.atlassian.net';
|
|
55
|
-
const jiraEmail = process.env.JIRA_API_EMAIL;
|
|
56
|
-
const jiraApiKey = process.env.JIRA_API_KEY;
|
|
57
|
-
const jiraFullApiKey = `${jiraEmail}:${jiraApiKey}`;
|
|
58
|
-
const jiraUrl = `${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`;
|
|
59
|
-
|
|
60
|
-
const jiraResponse = await fetch(jiraUrl, {
|
|
61
|
-
headers: {
|
|
62
|
-
Authorization: `Basic ${Buffer.from(jiraFullApiKey).toString('base64')}`,
|
|
63
|
-
'Content-Type': 'application/json',
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
if (!jiraResponse.ok) {
|
|
68
|
-
throw new Error(
|
|
69
|
-
`Failed to fetch Jira ticket ${jiraTicketId}. Status: ${jiraResponse.status}, Ticket URL: ${jiraUrl}`,
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return await jiraResponse.json();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Generates release notes using OpenAI
|
|
78
|
-
*/
|
|
79
|
-
async function generateReleaseNotes(jiraTicketData) {
|
|
80
|
-
const openaiClient = new OpenAI({
|
|
81
|
-
apiKey: process.env['OPENAI_API_KEY'],
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const ChangeRequestSchema = z.object({
|
|
85
|
-
change_type: z.enum(['patch', 'minor']),
|
|
86
|
-
summary: z.string(),
|
|
87
|
-
jira_ticket_id: z.string(),
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const openAiResponse = await openaiClient.chat.completions.create({
|
|
91
|
-
model: 'gpt-4o-mini',
|
|
92
|
-
messages: [
|
|
93
|
-
{
|
|
94
|
-
role: 'system',
|
|
95
|
-
content: `Process JSON from a Jira ticket to generate simple maximum 2 sentence release note for the ticket and determine the change type for bug it should be a patch for new feature it should be a minor change`,
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
role: 'user',
|
|
99
|
-
content: JSON.stringify(jiraTicketData),
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
response_format: zodResponseFormat(ChangeRequestSchema, 'changeset_schema'),
|
|
103
|
-
temperature: 0,
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
const assistantResponse = openAiResponse.choices[0].message.content;
|
|
107
|
-
return JSON.parse(assistantResponse);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Writes the changeset file
|
|
112
|
-
*/
|
|
113
|
-
async function writeJiraChangesetFile(
|
|
114
|
-
packages,
|
|
115
|
-
jiraTicketId,
|
|
116
|
-
changeType,
|
|
117
|
-
summary,
|
|
118
|
-
) {
|
|
119
|
-
const text = `${summary} [${jiraTicketId}]`;
|
|
120
|
-
await writeChangesetFile(packages, jiraTicketId, changeType, text);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export async function writeChangesetFile(packages, filename, changeType, text) {
|
|
124
|
-
const packageEntries = packages
|
|
125
|
-
.map((pkg) => `'${pkg.name}': ${changeType}`)
|
|
126
|
-
.join('\n');
|
|
127
|
-
|
|
128
|
-
const changesetContent = `---
|
|
129
|
-
${packageEntries}
|
|
130
|
-
---
|
|
131
|
-
|
|
132
|
-
${text}
|
|
133
|
-
`;
|
|
134
|
-
|
|
135
|
-
const changesetFile = `./.changeset/${filename}.md`;
|
|
136
|
-
|
|
137
|
-
await createChangesetDirectory();
|
|
138
|
-
await fs.promises.writeFile(changesetFile, changesetContent);
|
|
139
|
-
console.log(`Created changeset file at ${changesetFile}`);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Main function to create a changeset
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
|
-
export async function createChangeset() {
|
|
147
|
-
const packages = getPackageNames();
|
|
148
|
-
|
|
149
|
-
if (packages.length > 1) {
|
|
150
|
-
const allPackages = packages;
|
|
151
|
-
const response = await inquirer.prompt([
|
|
152
|
-
{
|
|
153
|
-
type: 'checkbox',
|
|
154
|
-
name: 'packages',
|
|
155
|
-
message: 'Which packages do you want to generate changesets for?',
|
|
156
|
-
choices: allPackages.map((appPackage) => ({
|
|
157
|
-
name: appPackage.name,
|
|
158
|
-
value: appPackage.name,
|
|
159
|
-
})),
|
|
160
|
-
validate: (input) => {
|
|
161
|
-
if (input.length === 0) {
|
|
162
|
-
return 'Please select at least one package.';
|
|
163
|
-
}
|
|
164
|
-
return true;
|
|
165
|
-
},
|
|
166
|
-
},
|
|
167
|
-
]);
|
|
168
|
-
|
|
169
|
-
const selectedPackages = allPackages.filter((appPackage) =>
|
|
170
|
-
response.packages.includes(appPackage.name),
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
// Get package contents for all selected packages
|
|
174
|
-
const selectedPackageContents = await Promise.all(
|
|
175
|
-
selectedPackages.map(async (selectedPackage) => {
|
|
176
|
-
return await getPackage(selectedPackage.path);
|
|
177
|
-
}),
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
await createChangesetForPackage(selectedPackageContents);
|
|
181
|
-
} else {
|
|
182
|
-
const mainPackage = await getMainPackage();
|
|
183
|
-
await createChangesetForPackage([mainPackage]);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export async function createChangesetForPackage(packages) {
|
|
188
|
-
try {
|
|
189
|
-
// Step 1: Get the current branch name
|
|
190
|
-
const branchName = await getCurrentBranch();
|
|
191
|
-
|
|
192
|
-
// Step 2: Extract Jira ticket number
|
|
193
|
-
const jiraTicketId = extractJiraTicketId(branchName);
|
|
194
|
-
|
|
195
|
-
// Step 3: Fetch Jira ticket data
|
|
196
|
-
const jiraTicketData = await fetchJiraTicketData(jiraTicketId);
|
|
197
|
-
const jiraSummary = jiraTicketData.fields.summary;
|
|
198
|
-
console.log(
|
|
199
|
-
`Generating release notes for ${jiraTicketId} - ${jiraSummary}`,
|
|
200
|
-
);
|
|
201
|
-
|
|
202
|
-
// Step 4: Generate release notes using OpenAI
|
|
203
|
-
const { change_type, summary } = await generateReleaseNotes(jiraTicketData);
|
|
204
|
-
console.log(`Change type: ${change_type}`);
|
|
205
|
-
console.log(`Release note: ${summary}`);
|
|
206
|
-
|
|
207
|
-
// Step 5: Create a changeset .md file for all packages
|
|
208
|
-
await writeJiraChangesetFile(packages, jiraTicketId, change_type, summary);
|
|
209
|
-
|
|
210
|
-
console.log('Changeset created successfully!');
|
|
211
|
-
} catch (err) {
|
|
212
|
-
console.error(`Error: ${err.message}`);
|
|
213
|
-
process.exit(1);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
export function getPackageNames(rootPath = '.') {
|
|
5
|
-
const appsDir = path.join(rootPath, 'apps');
|
|
6
|
-
const packagesDir = path.join(rootPath, 'packages');
|
|
7
|
-
const rootPackageJson = path.join(rootPath, 'package.json');
|
|
8
|
-
|
|
9
|
-
// Check if this is a monorepo (has apps and/or packages directories)
|
|
10
|
-
const hasAppsDir =
|
|
11
|
-
fs.existsSync(appsDir) && fs.statSync(appsDir).isDirectory();
|
|
12
|
-
const hasPackagesDir =
|
|
13
|
-
fs.existsSync(packagesDir) && fs.statSync(packagesDir).isDirectory();
|
|
14
|
-
|
|
15
|
-
if (hasAppsDir || hasPackagesDir) {
|
|
16
|
-
// This is a monorepo
|
|
17
|
-
const packages = [];
|
|
18
|
-
|
|
19
|
-
// Get packages from apps directory
|
|
20
|
-
if (hasAppsDir) {
|
|
21
|
-
const appsPackages = getPackagesFromDirectory(appsDir);
|
|
22
|
-
packages.push(...appsPackages);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Get packages from packages directory
|
|
26
|
-
if (hasPackagesDir) {
|
|
27
|
-
const packagesPackages = getPackagesFromDirectory(packagesDir);
|
|
28
|
-
packages.push(...packagesPackages);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return packages;
|
|
32
|
-
} else {
|
|
33
|
-
// This is not a monorepo, return single package
|
|
34
|
-
if (fs.existsSync(rootPackageJson)) {
|
|
35
|
-
try {
|
|
36
|
-
const packageJson = JSON.parse(
|
|
37
|
-
fs.readFileSync(rootPackageJson, 'utf8'),
|
|
38
|
-
);
|
|
39
|
-
return packageJson.name
|
|
40
|
-
? [{ name: packageJson.name, path: rootPath, content: packageJson }]
|
|
41
|
-
: [];
|
|
42
|
-
} catch (error) {
|
|
43
|
-
console.error('Error reading root package.json:', error);
|
|
44
|
-
return [];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function getPackagesFromDirectory(dirPath) {
|
|
52
|
-
const packages = [];
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const items = fs.readdirSync(dirPath);
|
|
56
|
-
|
|
57
|
-
for (const item of items) {
|
|
58
|
-
const itemPath = path.join(dirPath, item);
|
|
59
|
-
const packageJsonPath = path.join(itemPath, 'package.json');
|
|
60
|
-
|
|
61
|
-
// Check if item is a directory and has package.json
|
|
62
|
-
if (
|
|
63
|
-
fs.statSync(itemPath).isDirectory() &&
|
|
64
|
-
fs.existsSync(packageJsonPath)
|
|
65
|
-
) {
|
|
66
|
-
try {
|
|
67
|
-
const packageJson = JSON.parse(
|
|
68
|
-
fs.readFileSync(packageJsonPath, 'utf8'),
|
|
69
|
-
);
|
|
70
|
-
if (packageJson.name) {
|
|
71
|
-
packages.push({
|
|
72
|
-
name: packageJson.name,
|
|
73
|
-
path: itemPath,
|
|
74
|
-
content: packageJson,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
} catch (error) {
|
|
78
|
-
console.error(`Error reading package.json in ${itemPath}:`, error);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error(`Error reading directory ${dirPath}:`, error);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return packages;
|
|
87
|
-
}
|
package/src/changeset/util.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
|
|
4
|
-
async function fileExists(filePath) {
|
|
5
|
-
try {
|
|
6
|
-
await fs.promises.access(filePath);
|
|
7
|
-
return true;
|
|
8
|
-
} catch {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export async function getMainPackage() {
|
|
13
|
-
const mainModulePath = process.cwd();
|
|
14
|
-
return getPackage(mainModulePath);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function getPackage(mainModulePath) {
|
|
18
|
-
if (mainModulePath) {
|
|
19
|
-
const packageJsonPath = path.join(mainModulePath, 'package.json');
|
|
20
|
-
if (await fileExists(packageJsonPath)) {
|
|
21
|
-
const fileContent = await fs.promises.readFile(packageJsonPath, 'utf-8');
|
|
22
|
-
const packageJson = JSON.parse(fileContent);
|
|
23
|
-
return packageJson;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
throw new Error('Main package.json not found');
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Locates and extracts a JIRA Ticket ID from a given string.
|
|
31
|
-
* <p>
|
|
32
|
-
* The JIRA Ticket ID is expected to follow the pattern of uppercase letters (at least two) followed by a hyphen and digits (e.g., DC-1234, INFP-9).
|
|
33
|
-
* @param str the string to search for a JIRA ticket ID
|
|
34
|
-
* @returns {JIRA-TicketID|null}
|
|
35
|
-
*/
|
|
36
|
-
export function findJiraTicketId(str) {
|
|
37
|
-
if (!str) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
const regex = /([A-Z]{2,}-\d+)/;
|
|
41
|
-
const matches = str.match(regex);
|
|
42
|
-
return matches ? matches[0] : null;
|
|
43
|
-
}
|
package/src/changeset/version.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { setGitInfo } from '../next/util.js';
|
|
2
|
-
import { $ } from 'zx';
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { updateComponentVersion } from '../next/jira.js';
|
|
5
|
-
import { findJiraTicketId } from './util.js';
|
|
6
|
-
import { revertBaseBranch, updateBaseBranch } from './changeset-config.js';
|
|
7
|
-
import semver from 'semver';
|
|
8
|
-
|
|
9
|
-
const changeSetPackage = `{
|
|
10
|
-
"name": "changeset-package",
|
|
11
|
-
"version": "1.0.0",
|
|
12
|
-
"description": "",
|
|
13
|
-
"scripts": {
|
|
14
|
-
},
|
|
15
|
-
"type": "module",
|
|
16
|
-
"keywords": [],
|
|
17
|
-
"author": "",
|
|
18
|
-
"license": "ISC",
|
|
19
|
-
"dependencies": {},
|
|
20
|
-
"devDependencies": {
|
|
21
|
-
"@changesets/cli": "^2.27.10"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
`;
|
|
25
|
-
|
|
26
|
-
export function toShortVersion(version) {
|
|
27
|
-
const parsed = semver.parse(version);
|
|
28
|
-
if (!parsed) return null;
|
|
29
|
-
return `${parsed.major}.${parsed.minor}`;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export async function versionStatus(sinceBranch) {
|
|
33
|
-
const outputPath = './changeset-output.json';
|
|
34
|
-
|
|
35
|
-
if (sinceBranch) {
|
|
36
|
-
await $`pnpm changeset status --output=${outputPath} --since=${sinceBranch}`;
|
|
37
|
-
} else {
|
|
38
|
-
await $`pnpm changeset status --output=${outputPath}`;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Read the file and parse JSON
|
|
42
|
-
const jsonOutput = JSON.parse(await fs.promises.readFile(outputPath, 'utf8'));
|
|
43
|
-
|
|
44
|
-
await fs.promises.rm(outputPath);
|
|
45
|
-
return jsonOutput.releases;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function versionCommand(closeVersion = false) {
|
|
49
|
-
console.log('📦 Running Changeset versioning...');
|
|
50
|
-
if (!process.env.IS_DEV) {
|
|
51
|
-
await setGitInfo();
|
|
52
|
-
await $`mv package.json package.json.bak`;
|
|
53
|
-
await $`mv pnpm-lock.yaml pnpm-lock.yaml.bak`;
|
|
54
|
-
await fs.promises.writeFile('package.json', changeSetPackage);
|
|
55
|
-
await $`pnpm install`;
|
|
56
|
-
await $`rm package.json pnpm-lock.yaml`;
|
|
57
|
-
await $`mv package.json.bak package.json`;
|
|
58
|
-
await $`mv pnpm-lock.yaml.bak pnpm-lock.yaml`;
|
|
59
|
-
}
|
|
60
|
-
if (closeVersion) {
|
|
61
|
-
await $`pnpm changeset pre exit`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let originalBaseBranch;
|
|
65
|
-
try {
|
|
66
|
-
originalBaseBranch = updateBaseBranch();
|
|
67
|
-
const releases = await versionStatus();
|
|
68
|
-
revertBaseBranch(originalBaseBranch);
|
|
69
|
-
await $`pnpm changeset version`;
|
|
70
|
-
|
|
71
|
-
return releases;
|
|
72
|
-
} catch {
|
|
73
|
-
revertBaseBranch(originalBaseBranch);
|
|
74
|
-
return [];
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function updateJiraWithVersion(releases) {
|
|
79
|
-
const lastCommit = (await $`git log -1 --pretty=%B`).stdout.trim();
|
|
80
|
-
console.log(`Last commit '${lastCommit}' being processed to get Jira ticket`);
|
|
81
|
-
|
|
82
|
-
const jiraTicketId = findJiraTicketId(lastCommit);
|
|
83
|
-
|
|
84
|
-
// If we have all the necessary data, update the component version in Jira
|
|
85
|
-
if (jiraTicketId) {
|
|
86
|
-
for (const release of releases) {
|
|
87
|
-
try {
|
|
88
|
-
await updateComponentVersion(
|
|
89
|
-
jiraTicketId,
|
|
90
|
-
release.name,
|
|
91
|
-
release.newVersion,
|
|
92
|
-
);
|
|
93
|
-
} catch (error) {
|
|
94
|
-
console.error(
|
|
95
|
-
`Failed to update Jira component version: ${error.message}`,
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
console.log('✅ Changeset versioning complete.');
|
|
102
|
-
}
|
package/src/lib/merge-driver.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from 'fs';
|
|
4
|
-
import { execSync } from 'child_process';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { fileURLToPath } from 'url';
|
|
7
|
-
|
|
8
|
-
// Get __dirname equivalent in ESM
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = path.dirname(__filename);
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Default merge logic function - can be overridden
|
|
14
|
-
* @param {string} headContent - The content from HEAD (current branch)
|
|
15
|
-
* @param {string} branchContent - The content from the incoming branch
|
|
16
|
-
* @returns {string} - The merged content
|
|
17
|
-
* @throws {Error} - If the conflict cannot be automatically merged
|
|
18
|
-
*/
|
|
19
|
-
export function defaultMergeLogic(headContent, branchContent) {
|
|
20
|
-
// Default implementation - throws error
|
|
21
|
-
// Users should provide their own implementation
|
|
22
|
-
throw new Error(
|
|
23
|
-
'No merge logic provided - please pass a custom merge function',
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Main merge driver function
|
|
29
|
-
* @param {string} filePath - Path to the file with conflicts
|
|
30
|
-
* @param {Function} customMergeLogic - Custom merge function (optional)
|
|
31
|
-
* @returns {Promise<{success: boolean, totalConflicts: number, resolvedConflicts: number, hasUnresolvedConflicts: boolean}>}
|
|
32
|
-
*/
|
|
33
|
-
export async function mergeDriver(filePath, customMergeLogic = null) {
|
|
34
|
-
// Use provided merge logic or fall back to default
|
|
35
|
-
const mergeLogic = customMergeLogic || defaultMergeLogic;
|
|
36
|
-
|
|
37
|
-
if (!filePath) {
|
|
38
|
-
throw new Error('File path is required');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Check if file exists
|
|
42
|
-
if (!fs.existsSync(filePath)) {
|
|
43
|
-
throw new Error(`File not found: ${filePath}`);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
console.log(`Processing conflicts in: ${filePath}`);
|
|
47
|
-
|
|
48
|
-
// Read the file content
|
|
49
|
-
let fileContent;
|
|
50
|
-
try {
|
|
51
|
-
fileContent = fs.readFileSync(filePath, 'utf8');
|
|
52
|
-
} catch (error) {
|
|
53
|
-
throw new Error(`Error reading file: ${error.message}`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Split content into lines for processing
|
|
57
|
-
const lines = fileContent.split('\n');
|
|
58
|
-
const resultLines = [];
|
|
59
|
-
|
|
60
|
-
// Track merge state
|
|
61
|
-
let hasUnresolvedConflicts = false;
|
|
62
|
-
let totalConflicts = 0;
|
|
63
|
-
let resolvedConflicts = 0;
|
|
64
|
-
|
|
65
|
-
// State variables for parsing
|
|
66
|
-
let inConflict = false;
|
|
67
|
-
let headLines = [];
|
|
68
|
-
let branchLines = [];
|
|
69
|
-
let currentSection = null; // 'head' or 'branch'
|
|
70
|
-
|
|
71
|
-
// Process each line
|
|
72
|
-
for (let i = 0; i < lines.length; i++) {
|
|
73
|
-
const line = lines[i];
|
|
74
|
-
|
|
75
|
-
if (line.startsWith('<<<<<<<')) {
|
|
76
|
-
// Start of conflict marker
|
|
77
|
-
inConflict = true;
|
|
78
|
-
currentSection = 'head';
|
|
79
|
-
headLines = [];
|
|
80
|
-
branchLines = [];
|
|
81
|
-
totalConflicts++;
|
|
82
|
-
} else if (inConflict && line.startsWith('=======')) {
|
|
83
|
-
// Middle of conflict - switch from HEAD to branch
|
|
84
|
-
currentSection = 'branch';
|
|
85
|
-
} else if (inConflict && line.startsWith('>>>>>>>')) {
|
|
86
|
-
// End of conflict marker - attempt to merge
|
|
87
|
-
const headContent = headLines.join('\n');
|
|
88
|
-
const branchContent = branchLines.join('\n');
|
|
89
|
-
|
|
90
|
-
try {
|
|
91
|
-
// Call custom merge logic
|
|
92
|
-
const mergedContent = mergeLogic(headContent, branchContent);
|
|
93
|
-
|
|
94
|
-
// Add merged content to result
|
|
95
|
-
if (mergedContent !== null && mergedContent !== undefined) {
|
|
96
|
-
resultLines.push(mergedContent);
|
|
97
|
-
resolvedConflicts++;
|
|
98
|
-
console.log(`✓ Resolved conflict #${totalConflicts}`);
|
|
99
|
-
}
|
|
100
|
-
} catch (error) {
|
|
101
|
-
// Cannot merge this conflict - keep original conflict markers
|
|
102
|
-
hasUnresolvedConflicts = true;
|
|
103
|
-
|
|
104
|
-
console.log(
|
|
105
|
-
`✗ Could not resolve conflict #${totalConflicts}: ${error.message}`,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
// Preserve the original conflict
|
|
109
|
-
resultLines.push(`<<<<<<< HEAD`);
|
|
110
|
-
resultLines.push(headContent);
|
|
111
|
-
resultLines.push('=======');
|
|
112
|
-
resultLines.push(branchContent);
|
|
113
|
-
resultLines.push(`>>>>>>> branch`);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Reset conflict state
|
|
117
|
-
inConflict = false;
|
|
118
|
-
currentSection = null;
|
|
119
|
-
headLines = [];
|
|
120
|
-
branchLines = [];
|
|
121
|
-
} else if (inConflict) {
|
|
122
|
-
// Inside conflict - collect lines
|
|
123
|
-
if (currentSection === 'head') {
|
|
124
|
-
headLines.push(line);
|
|
125
|
-
} else if (currentSection === 'branch') {
|
|
126
|
-
branchLines.push(line);
|
|
127
|
-
}
|
|
128
|
-
} else {
|
|
129
|
-
// Normal line outside of conflict
|
|
130
|
-
resultLines.push(line);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Write the result back to the file
|
|
135
|
-
const resultContent = resultLines.join('\n');
|
|
136
|
-
try {
|
|
137
|
-
fs.writeFileSync(filePath, resultContent, 'utf8');
|
|
138
|
-
console.log(`\nFile updated: ${filePath}`);
|
|
139
|
-
} catch (error) {
|
|
140
|
-
throw new Error(`Error writing file: ${error.message}`);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// Summary
|
|
144
|
-
console.log('\n--- Merge Summary ---');
|
|
145
|
-
console.log(`Total conflicts found: ${totalConflicts}`);
|
|
146
|
-
console.log(`Conflicts resolved: ${resolvedConflicts}`);
|
|
147
|
-
console.log(`Conflicts remaining: ${totalConflicts - resolvedConflicts}`);
|
|
148
|
-
|
|
149
|
-
// If all conflicts were resolved, stage the file
|
|
150
|
-
if (!hasUnresolvedConflicts && totalConflicts > 0) {
|
|
151
|
-
try {
|
|
152
|
-
execSync(`git add "${filePath}"`, { stdio: 'inherit' });
|
|
153
|
-
console.log(
|
|
154
|
-
`\n✓ All conflicts resolved! File has been staged with 'git add'.`,
|
|
155
|
-
);
|
|
156
|
-
} catch (error) {
|
|
157
|
-
console.error(`\nWarning: Could not stage file: ${error.message}`);
|
|
158
|
-
console.log('You may need to run "git add" manually.');
|
|
159
|
-
}
|
|
160
|
-
} else if (hasUnresolvedConflicts) {
|
|
161
|
-
console.log(`\n⚠ Some conflicts could not be resolved automatically.`);
|
|
162
|
-
console.log('Please review and resolve the remaining conflicts manually.');
|
|
163
|
-
} else if (totalConflicts === 0) {
|
|
164
|
-
console.log('\nNo conflicts found in the file.');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Return result object for programmatic use
|
|
168
|
-
return {
|
|
169
|
-
success: !hasUnresolvedConflicts,
|
|
170
|
-
totalConflicts,
|
|
171
|
-
resolvedConflicts,
|
|
172
|
-
hasUnresolvedConflicts,
|
|
173
|
-
filePath,
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Process multiple files with the same merge logic
|
|
179
|
-
* @param {string[]} filePaths - Array of file paths to process
|
|
180
|
-
* @param {Function} customMergeLogic - Custom merge function
|
|
181
|
-
* @returns {Promise<Array>} - Array of results for each file
|
|
182
|
-
*/
|
|
183
|
-
export async function mergeMultipleFiles(filePaths, customMergeLogic) {
|
|
184
|
-
const results = [];
|
|
185
|
-
|
|
186
|
-
for (const filePath of filePaths) {
|
|
187
|
-
try {
|
|
188
|
-
const result = await mergeDriver(filePath, customMergeLogic);
|
|
189
|
-
results.push(result);
|
|
190
|
-
} catch (error) {
|
|
191
|
-
console.error(`Error processing ${filePath}: ${error.message}`);
|
|
192
|
-
results.push({
|
|
193
|
-
success: false,
|
|
194
|
-
error: error.message,
|
|
195
|
-
filePath,
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return results;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Default export for convenience
|
|
204
|
-
export default mergeDriver;
|