@docupace/pipeline 1.0.0-alpha.56 → 1.0.0-alpha.58
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/bin/next-changeset-validate.sh +2 -1
- package/next/changeset.sh +75 -0
- package/package.json +1 -1
- package/src/changeset/cli.js +88 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
6
|
+
|
|
7
|
+
# Function: Validate changeset presence
|
|
8
|
+
validate_changesets() {
|
|
9
|
+
if [ ! -z "$PR_ID" ]; then
|
|
10
|
+
echo "🔍 Validating changesets..."
|
|
11
|
+
pnpm node $DIR/validateChangeset.cjs $1 || {
|
|
12
|
+
if [ $? -eq 1 ]; then
|
|
13
|
+
echo "❌ No changeset found. Please add a changeset to this PR. Please see more information at https://docupacellc.atlassian.net/wiki/spaces/PM/pages/1350893571/Creating+changesets+for+Docupace+Next"
|
|
14
|
+
exit 1
|
|
15
|
+
else
|
|
16
|
+
echo "✅ Changeset validation passed."
|
|
17
|
+
fi
|
|
18
|
+
}
|
|
19
|
+
fi
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
setGitInfo() {
|
|
23
|
+
git config --global user.email "gitops@docupace.com"
|
|
24
|
+
git config --global user.name "Gitops"
|
|
25
|
+
git remote set-url origin https://x-token-auth:${BITBUCKET_TOKEN}@bitbucket.org/dp-cloud/docupace-graphql-server.git
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# Function: Handle versioning and changelog generation
|
|
29
|
+
version_application() {
|
|
30
|
+
setGitInfo
|
|
31
|
+
echo "📦 Running Changeset versioning..."
|
|
32
|
+
pnpm changeset version
|
|
33
|
+
echo "Complete"
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# Function: Commit and tag the new version
|
|
37
|
+
commit_and_tag() {
|
|
38
|
+
setGitInfo
|
|
39
|
+
echo "📌 Committing and tagging the new version..."
|
|
40
|
+
git add .
|
|
41
|
+
git commit -m "chore: version bump and changelog"
|
|
42
|
+
git push origin
|
|
43
|
+
|
|
44
|
+
# Create and push a new tag
|
|
45
|
+
local new_version
|
|
46
|
+
new_version=$(node -p "require('./package.json').version")
|
|
47
|
+
git tag "v$new_version"
|
|
48
|
+
git push origin --tags
|
|
49
|
+
echo "✅ Version $new_version tagged and pushed."
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Parse the provided command
|
|
53
|
+
case "$1" in
|
|
54
|
+
validate)
|
|
55
|
+
validate_changesets $2
|
|
56
|
+
;;
|
|
57
|
+
build)
|
|
58
|
+
build_application
|
|
59
|
+
;;
|
|
60
|
+
version)
|
|
61
|
+
version_application
|
|
62
|
+
;;
|
|
63
|
+
commit-and-tag)
|
|
64
|
+
commit_and_tag
|
|
65
|
+
;;
|
|
66
|
+
all)
|
|
67
|
+
version_application
|
|
68
|
+
commit_and_tag
|
|
69
|
+
;;
|
|
70
|
+
*)
|
|
71
|
+
echo "❓ Unknown command: $1"
|
|
72
|
+
echo "Available commands: validate, build, version, commit-and-tag, all"
|
|
73
|
+
exit 1
|
|
74
|
+
;;
|
|
75
|
+
esac
|
package/package.json
CHANGED
package/src/changeset/cli.js
CHANGED
|
@@ -106,5 +106,93 @@ program
|
|
|
106
106
|
await commitTagCommand();
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
+
program
|
|
110
|
+
.name('create-changeset')
|
|
111
|
+
.description('Creates a changeset based on the current branch and Jira ticket information')
|
|
112
|
+
.action(async () => {
|
|
113
|
+
try {
|
|
114
|
+
// Step 1: Get the current branch name
|
|
115
|
+
const branchName = (await $`git branch --show-current`).stdout.trim();
|
|
116
|
+
console.log(`Current branch: ${branchName}`);
|
|
117
|
+
|
|
118
|
+
// Step 2: Extract Jira ticket number (e.g., matching JIRA-1234 pattern)
|
|
119
|
+
const jiraTicketMatch = branchName.match(/([A-Z]+-\d+)/);
|
|
120
|
+
if (!jiraTicketMatch) {
|
|
121
|
+
throw new Error('No Jira ticket found in the branch name.');
|
|
122
|
+
}
|
|
123
|
+
const jiraTicketId = jiraTicketMatch[0];
|
|
124
|
+
console.log(`Extracted Jira ticket ID: ${jiraTicketId}`);
|
|
125
|
+
|
|
126
|
+
// Step 3: Fetch Jira ticket information
|
|
127
|
+
const jiraBaseUrl = process.env.JIRA_BASE_URL;
|
|
128
|
+
const jiraApiKey = process.env.JIRA_API_KEY;
|
|
129
|
+
const jiraResponse = await fetch(`${jiraBaseUrl}/rest/api/2/issue/${jiraTicketId}`, {
|
|
130
|
+
headers: {
|
|
131
|
+
Authorization: `Basic ${Buffer.from(jiraApiKey).toString('base64')}`,
|
|
132
|
+
'Content-Type': 'application/json',
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
if (!jiraResponse.ok) {
|
|
137
|
+
throw new Error(`Failed to fetch Jira ticket. Status: ${jiraResponse.status}`);
|
|
138
|
+
}
|
|
139
|
+
const jiraTicketData = await jiraResponse.json();
|
|
140
|
+
const summary = jiraTicketData.fields.summary;
|
|
141
|
+
console.log(`Jira ticket summary: ${summary}`);
|
|
142
|
+
|
|
143
|
+
// Step 4: Call OpenAI to determine change type
|
|
144
|
+
const openAiApiKey = process.env.OPENAI_API_KEY;
|
|
145
|
+
const openAiResponse = await fetch('https://api.openai.com/v1/assistants/asst_ronjCuCINK5pjLusTB9XCGYG/completions', {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
headers: {
|
|
148
|
+
Authorization: `Bearer ${openAiApiKey}`,
|
|
149
|
+
'Content-Type': 'application/json',
|
|
150
|
+
},
|
|
151
|
+
body: JSON.stringify({
|
|
152
|
+
schema: {
|
|
153
|
+
name: 'change_request',
|
|
154
|
+
strict: true,
|
|
155
|
+
schema: {
|
|
156
|
+
type: 'object',
|
|
157
|
+
properties: {
|
|
158
|
+
change_type: { type: 'string', enum: ['patch', 'minor'] },
|
|
159
|
+
summary: { type: 'string' },
|
|
160
|
+
jira_ticket_id: { type: 'string' },
|
|
161
|
+
},
|
|
162
|
+
required: ['change_type', 'summary', 'jira_ticket_id'],
|
|
163
|
+
additionalProperties: false,
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
data: jiraTicketData,
|
|
167
|
+
}),
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (!openAiResponse.ok) {
|
|
171
|
+
throw new Error(`Failed to call OpenAI assistant. Status: ${openAiResponse.status}`);
|
|
172
|
+
}
|
|
173
|
+
const openAiData = await openAiResponse.json();
|
|
174
|
+
const { change_type } = openAiData.result;
|
|
175
|
+
console.log(`Determined change type: ${change_type}`);
|
|
176
|
+
|
|
177
|
+
// Step 5: Create a changeset using pnpm
|
|
178
|
+
const changesetContent = `---
|
|
179
|
+
"${jiraTicketId}": ${change_type}
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
${summary}
|
|
183
|
+
`;
|
|
184
|
+
const changesetFile = `./.changeset/${jiraTicketId}.md`;
|
|
185
|
+
|
|
186
|
+
await $`mkdir -p ./.changeset`;
|
|
187
|
+
await $`echo ${JSON.stringify(changesetContent)} > ${changesetFile}`;
|
|
188
|
+
console.log(`Created changeset file at ${changesetFile}`);
|
|
189
|
+
|
|
190
|
+
console.log('Done!');
|
|
191
|
+
} catch (err) {
|
|
192
|
+
console.error(`Error: ${err.message}`);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
|
|
109
197
|
// Parse arguments
|
|
110
198
|
program.parse(args);
|