@jira-deploy/core 1.0.18 → 1.0.20

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/jira-client.js CHANGED
@@ -79,7 +79,7 @@ export class JiraClient {
79
79
  // 查詢 issue 目前狀態
80
80
  async getIssue(issueKey) {
81
81
  const res = await this.http.get(`/issue/${issueKey}`, {
82
- params: { fields: 'status,summary,assignee,comment' },
82
+ params: { fields: 'status,summary,assignee,comment,issuetype' },
83
83
  });
84
84
  return res.data;
85
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jira-deploy/core",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "repository": {
package/tools/ci.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * - create_ci_ticket
4
4
  * - build_ci
5
5
  */
6
- import { error, getPollIntervalMs, getPollTimeoutMs, isFailingResult, isPassingResult, ok, today, } from './helpers.js';
6
+ import { error, getPollIntervalMs, getPollTimeoutMs, isFailingResult, isPassingResult, ok, today, validateIssueType, } from './helpers.js';
7
7
  import {
8
8
  findAnyTransition as findAnyTransitionForIssue,
9
9
  sleep,
@@ -14,6 +14,7 @@ import {
14
14
  DEPT_CODES,
15
15
  ENV_CODES,
16
16
  FIELD_OPTIONS,
17
+ ISSUE_TYPES,
17
18
  ISSUE_TYPE_IDS,
18
19
  JIRA_PROJECT_ID,
19
20
  REPO_MAPS,
@@ -22,7 +23,7 @@ import {
22
23
  SYSTEM_TO_CI_REPO_MAP,
23
24
  SYSTEM_TO_DEPT_MAP,
24
25
  } from '../constants/index.js';
25
- import {getRuntimeConfigValue} from '../constants/config.js';
26
+ import { getRuntimeConfigValue } from '../constants/config.js';
26
27
  import { assertNoOpenPRBeforeCreate } from './branch-prs.js';
27
28
 
28
29
  // ── Flow Definition ──────────────────────────────────────────────
@@ -176,8 +177,10 @@ export function getCIToolDefinitions() {
176
177
 
177
178
  export async function handleBuildCI(args, ctx) {
178
179
  const { issueKey } = args;
180
+ const { jira } = ctx;
179
181
 
180
182
  try {
183
+ await validateIssueType(issueKey, ISSUE_TYPES.CI, jira);
181
184
  const result = await executeCIBuildFlow(issueKey, ctx);
182
185
  return ok(result);
183
186
  } catch (err) {
@@ -15,6 +15,7 @@ import {
15
15
  getDeployConfig,
16
16
  GRAY_RELEASE_FIELD_IDS,
17
17
  GRAY_RELEASE_MODULE_IDS,
18
+ ISSUE_TYPES,
18
19
  ISSUE_TYPE_IDS,
19
20
  JIRA_DEFAULTS,
20
21
  JIRA_PROJECT_ID,
@@ -35,12 +36,13 @@ import {
35
36
  isPassingResult,
36
37
  ok,
37
38
  today,
39
+ validateIssueType,
38
40
  } from './helpers.js';
39
41
  import { assertNoOpenPRBeforeCreate } from './branch-prs.js';
40
42
  import { Poller } from '../poller.js';
41
43
  import { handleGetReleaseManager, handleWaitForComment } from './release.js';
42
44
  import { handleSendJabberMessage } from './jabber.js';
43
- import {getRuntimeConfigValue} from '../constants/config.js';
45
+ import { getRuntimeConfigValue } from '../constants/config.js';
44
46
  import {
45
47
  needSwitchExecutionNode as shouldSwitchExecutionNode,
46
48
  waitForSwitchExecutionNode as waitForSharedSwitchExecutionNode,
@@ -658,8 +660,10 @@ export async function handleLinkStgGrayRelease(args, {
658
660
  */
659
661
  export async function handleBuildGrayRelease(args, ctx) {
660
662
  const { issueKey } = args;
663
+ const { jira } = ctx;
661
664
 
662
665
  try {
666
+ await validateIssueType(issueKey, ISSUE_TYPES.GRAY_RELEASE, jira);
663
667
  const result = await executeGrayReleaseBuildFlow(issueKey, ctx);
664
668
  return ok(result);
665
669
  } catch (err) {
@@ -715,9 +719,10 @@ export async function handleGetGrayReleaseStatus(args, { jira }) {
715
719
  */
716
720
  export async function handleDeployGrayRelease(args, ctx) {
717
721
  const { issueKey } = args;
718
- const { notifier } = ctx;
722
+ const { jira, notifier } = ctx;
719
723
 
720
724
  try {
725
+ await validateIssueType(issueKey, ISSUE_TYPES.GRAY_RELEASE, jira);
721
726
  progress(ctx, {
722
727
  phase: 'action',
723
728
  title: '開始 GrayRelease deploy 流程',
package/tools/helpers.js CHANGED
@@ -1,13 +1,19 @@
1
- import {getDeployConfig, META_TEST_NODES, SERVER_MODULE_MAP, SERVERS} from '../constants/index.js';
2
- import {getRuntimeConfigNumber} from '../constants/config.js';
1
+ import {
2
+ getDeployConfig,
3
+ ISSUE_TYPES,
4
+ META_TEST_NODES,
5
+ SERVER_MODULE_MAP,
6
+ SERVERS,
7
+ } from '../constants/index.js';
8
+ import { getRuntimeConfigNumber } from '../constants/config.js';
3
9
 
4
10
  export function ok(data) {
5
- return {content: [{type: 'text', text: JSON.stringify(data, null, 2)}]};
11
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
6
12
  }
7
13
 
8
14
  export function error(msg) {
9
15
  return {
10
- content: [{type: 'text', text: `❌ 錯誤: ${msg}`}],
16
+ content: [{ type: 'text', text: `❌ 錯誤: ${msg}` }],
11
17
  isError: true,
12
18
  };
13
19
  }
@@ -85,3 +91,34 @@ export function isFailingResult(value) {
85
91
  String(value ?? '').trim().toLowerCase(),
86
92
  );
87
93
  }
94
+
95
+ function inferIssueTypeFromIssue(issue) {
96
+ const summary = String(issue?.fields?.summary ?? '').trim();
97
+ if (!summary) {
98
+ return null;
99
+ }
100
+
101
+ if (/\bgray\s*release\b/i.test(summary)) {
102
+ return ISSUE_TYPES.GRAY_RELEASE;
103
+ }
104
+ if (/\blibrary\b/i.test(summary)) {
105
+ return ISSUE_TYPES.LIBRARY;
106
+ }
107
+ if (/\bci\b/i.test(summary)) {
108
+ return ISSUE_TYPES.CI;
109
+ }
110
+
111
+ return null;
112
+ }
113
+
114
+ export async function validateIssueType(issueKey, expectedType, jira) {
115
+ const issue = await jira.getIssue(issueKey);
116
+ const actualType = issue?.fields?.issuetype?.name ?? inferIssueTypeFromIssue(issue);
117
+
118
+ if (actualType !== expectedType) {
119
+ const normalizedActualType = String(actualType ?? 'Unknown');
120
+ throw new Error(`issue type 不符:預期 ${expectedType},但 ${issueKey} 是 ${normalizedActualType}`);
121
+ }
122
+
123
+ return issue;
124
+ }
package/tools/index.js CHANGED
@@ -315,6 +315,7 @@ export async function executeTool(name, args, deps) {
315
315
  issueKey: args.issueKey,
316
316
  status: issue.fields.status.name,
317
317
  summary: issue.fields.summary,
318
+ type: issue.fields.issuetype?.name ?? '',
318
319
  });
319
320
  }
320
321
 
package/tools/library.js CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  DEPT_CODES,
8
8
  ENV_CODES,
9
9
  FIELD_OPTIONS,
10
+ ISSUE_TYPES,
10
11
  ISSUE_TYPE_IDS,
11
12
  JIRA_PROJECT_ID,
12
13
  LIBRARY_FIELD_IDS,
@@ -19,8 +20,8 @@ import {
19
20
  SYSTEM_CODES,
20
21
  SYSTEM_TO_DEPT_MAP,
21
22
  } from '../constants/index.js';
22
- import {getRuntimeConfigValue} from '../constants/config.js';
23
- import { error, getPollIntervalMs, getPollTimeoutMs, ok, today } from './helpers.js';
23
+ import { getRuntimeConfigValue } from '../constants/config.js';
24
+ import { error, getPollIntervalMs, getPollTimeoutMs, ok, today, validateIssueType } from './helpers.js';
24
25
  import { assertNoOpenPRBeforeCreate } from './branch-prs.js';
25
26
  import {
26
27
  findAnyTransition as findAnyTransitionForIssue,
@@ -280,8 +281,10 @@ export async function handleCreateLibraryTicket(args, { jira, notifier }) {
280
281
 
281
282
  export async function handleBuildLibrary(args, ctx) {
282
283
  const { issueKey } = args;
284
+ const { jira } = ctx;
283
285
 
284
286
  try {
287
+ await validateIssueType(issueKey, ISSUE_TYPES.LIBRARY, jira);
285
288
  const result = await executeLibraryBuildFlow(issueKey, ctx);
286
289
  return ok(result);
287
290
  } catch (err) {