Skip to content

Commit

Permalink
issueKeys가 빈 스트링('')일 경우 버그 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kwanwooi25 committed Feb 24, 2023
1 parent 786404b commit 01ee8a2
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 76 deletions.
78 changes: 44 additions & 34 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71476,10 +71476,10 @@ function filterIssuesForComponent(jiraClient, issueKeys = []) {
return __awaiter(this, void 0, void 0, function* () {
const { componentName } = (0, getVariables_1.default)();
if (!issueKeys.length) {
(0, core_1.info)(`${const_1.colors.yellow}No issues to update`);
(0, core_1.info)(`${const_1.colors.yellow}업데이트할 이슈가 없습니다!`);
return [];
}
(0, core_1.info)(`${const_1.colors.white}⏳Filtering issues for ${componentName}...`);
(0, core_1.info)(`${const_1.colors.white}⏳${componentName}에 속한 이슈를 필터링 중...`);
const relatedIssues = yield Promise.all(issueKeys.map((issueKey) => __awaiter(this, void 0, void 0, function* () {
var _a, _b;
try {
Expand All @@ -71497,7 +71497,7 @@ function filterIssuesForComponent(jiraClient, issueKeys = []) {
}
})));
const filteredIssues = relatedIssues.map((issue) => issue === null || issue === void 0 ? void 0 : issue.key).filter(Boolean);
(0, core_1.info)(`${const_1.colors.green}✅ Found ${filteredIssues.length} issues out of ${issueKeys.length}!`);
(0, core_1.info)(`${const_1.colors.green}✅ ${issueKeys.length}개의 이슈 중 ${filteredIssues.length}개의 관련 이슈 필터링 완료!`);
return filteredIssues;
});
}
Expand Down Expand Up @@ -71530,15 +71530,15 @@ const getVariables_1 = __importDefault(__nccwpck_require__(20108));
function getProjectVersion(jiraClient) {
return __awaiter(this, void 0, void 0, function* () {
const { projectKey, versionName } = (0, getVariables_1.default)();
(0, core_1.info)(`${const_1.colors.white}Looking for project version ${versionName}...`);
(0, core_1.info)(`${const_1.colors.white}프로젝트 버전(${versionName}) 찾는중...`);
const projectVersions = yield jiraClient.projectVersions.getProjectVersions({
projectIdOrKey: projectKey,
});
const projectVersion = projectVersions.find((v) => v.name === versionName);
if (projectVersion) {
return projectVersion;
}
(0, core_1.info)(`${const_1.colors.yellow}Version ${versionName} not found, creating new one...`);
(0, core_1.info)(`${const_1.colors.yellow}프로젝트 버전(${versionName})이 존재하지 않아 새로 생성하는 중...`);
return yield jiraClient.projectVersions.createVersion({
name: versionName,
project: projectKey,
Expand Down Expand Up @@ -71572,7 +71572,7 @@ function getVariables() {
host,
email,
apiToken,
issueKeys: issueKeys.split(','),
issueKeys: issueKeys ? issueKeys.split(',') : [],
projectKey,
versionName,
componentName,
Expand Down Expand Up @@ -71616,7 +71616,7 @@ const updateIssues_1 = __importDefault(__nccwpck_require__(26564));
const jiraClient = (0, initJiraClient_1.default)();
const projectVersion = yield (0, getProjectVersion_1.default)(jiraClient);
if (!projectVersion) {
throw new Error(`🚫 Failed to find or create project version: ${versionName}`);
throw new Error(`🚫 프로젝트 버전(${versionName}) 조회 및 생성 실패!`);
}
const issueKeysToUpdate = !componentName
? issueKeys
Expand Down Expand Up @@ -71689,14 +71689,19 @@ const getVariables_1 = __importDefault(__nccwpck_require__(20108));
function releaseProjectVersion(jiraClient, projectVersion) {
return __awaiter(this, void 0, void 0, function* () {
const { projectKey } = (0, getVariables_1.default)();
(0, core_1.info)(`${const_1.colors.white}⏳ Releasing project version ${projectVersion.name}(${projectVersion.id})...`);
yield jiraClient.projectVersions.updateVersion({
id: projectVersion.id,
project: projectKey,
released: true,
releaseDate: (0, dayjs_1.default)().format('YYYY-MM-DD'),
});
(0, core_1.info)(`${const_1.colors.green}✅ Released project version ${projectVersion.name}(${projectVersion.id}) successfully!`);
(0, core_1.info)(`${const_1.colors.white}⏳ 프로젝트 버전(${projectVersion.name}) 릴리즈 중...`);
try {
yield jiraClient.projectVersions.updateVersion({
id: projectVersion.id,
project: projectKey,
released: true,
releaseDate: (0, dayjs_1.default)().format('YYYY-MM-DD'),
});
}
catch (error) {
(0, core_1.info)(`${const_1.colors.red}🚫 프로젝트 버전(${projectVersion.name}) 릴리즈 실패!`);
}
(0, core_1.info)(`${const_1.colors.green}✅ 프로젝트 버전(${projectVersion.name}) 릴리즈 성공!`);
});
}
exports["default"] = releaseProjectVersion;
Expand Down Expand Up @@ -71729,31 +71734,36 @@ function updateIssues(jiraClient, issueKeys = []) {
return __awaiter(this, void 0, void 0, function* () {
const { versionName, doneStatusName } = (0, getVariables_1.default)();
if (!issueKeys.length) {
(0, core_1.info)(`${const_1.colors.yellow}No issues to update`);
(0, core_1.info)(`${const_1.colors.yellow}업데이트할 이슈가 없습니다!`);
return;
}
(0, core_1.info)(`${const_1.colors.white}⏳ Updating related issues...`);
(0, core_1.info)(`${const_1.colors.white}⏳ 관련 JIRA 이슈를 업데이트하는 중...`);
yield Promise.all(issueKeys.map((issueKey) => __awaiter(this, void 0, void 0, function* () {
var _a;
(0, core_1.info)(`${const_1.colors.white} 👉 Updating ${issueKey}...`);
const issue = yield jiraClient.issues.getIssue({ issueIdOrKey: issueKey });
const transitions = yield jiraClient.issues.getTransitions({ issueIdOrKey: issueKey });
const doneTransition = (_a = transitions.transitions) === null || _a === void 0 ? void 0 : _a.find((t) => { var _a, _b; return (_b = (_a = t.name) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === null || _b === void 0 ? void 0 : _b.includes(doneStatusName.toLocaleLowerCase()); });
if (!doneTransition) {
return;
(0, core_1.info)(`${const_1.colors.white} 👉 ${issueKey} 업데이트 중...`);
try {
const issue = yield jiraClient.issues.getIssue({ issueIdOrKey: issueKey });
const transitions = yield jiraClient.issues.getTransitions({ issueIdOrKey: issueKey });
const doneTransition = (_a = transitions.transitions) === null || _a === void 0 ? void 0 : _a.find((t) => { var _a, _b; return (_b = (_a = t.name) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase()) === null || _b === void 0 ? void 0 : _b.includes(doneStatusName.toLocaleLowerCase()); });
if (!doneTransition) {
return;
}
return yield Promise.all([
yield jiraClient.issues.doTransition({
issueIdOrKey: issueKey,
transition: { id: doneTransition.id },
}),
yield jiraClient.issues.editIssue({
issueIdOrKey: issueKey,
fields: { fixVersions: [...issue.fields.fixVersions, { name: versionName }] },
}),
]);
}
catch (error) {
(0, core_1.info)(`${const_1.colors.red} 🚫 ${issueKey} 업데이트 실패!`);
}
return yield Promise.all([
yield jiraClient.issues.doTransition({
issueIdOrKey: issueKey,
transition: { id: doneTransition.id },
}),
yield jiraClient.issues.editIssue({
issueIdOrKey: issueKey,
fields: { fixVersions: [...issue.fields.fixVersions, { name: versionName }] },
}),
]);
})));
(0, core_1.info)(`✅ ${issueKeys.length} issues updated`);
(0, core_1.info)(`${const_1.colors.green}✅ ${issueKeys.length}개의 이슈 업데이트 완료!`);
});
}
exports["default"] = updateIssues;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jira-release",
"version": "1.0.1",
"version": "1.0.3",
"description": "Update JIRA issues and release project version",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 5 additions & 3 deletions src/filterIssuesForComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ export default async function filterIssuesForComponent(
const { componentName } = getVariables();

if (!issueKeys.length) {
info(`${colors.yellow}No issues to update`);
info(`${colors.yellow}업데이트할 이슈가 없습니다!`);
return [];
}

info(`${colors.white}Filtering issues for ${componentName}...`);
info(`${colors.white}${componentName}에 속한 이슈를 필터링 중...`);

const relatedIssues = await Promise.all(
issueKeys.map(async (issueKey) => {
Expand All @@ -36,7 +36,9 @@ export default async function filterIssuesForComponent(

const filteredIssues = relatedIssues.map((issue) => issue?.key).filter(Boolean);

info(`${colors.green}✅ Found ${filteredIssues.length} issues out of ${issueKeys.length}!`);
info(
`${colors.green}✅ 총 ${issueKeys.length}개의 이슈 중 ${filteredIssues.length}개의 관련 이슈 필터링 완료!`,
);

return filteredIssues as string[];
}
4 changes: 2 additions & 2 deletions src/getProjectVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import getVariables from './getVariables';
export default async function getProjectVersion(jiraClient: Version3Client) {
const { projectKey, versionName } = getVariables();

info(`${colors.white}Looking for project version ${versionName}...`);
info(`${colors.white}프로젝트 버전(${versionName}) 찾는중...`);

const projectVersions = await jiraClient.projectVersions.getProjectVersions({
projectIdOrKey: projectKey,
Expand All @@ -17,7 +17,7 @@ export default async function getProjectVersion(jiraClient: Version3Client) {
return projectVersion;
}

info(`${colors.yellow}Version ${versionName} not found, creating new one...`);
info(`${colors.yellow}프로젝트 버전(${versionName})이 존재하지 않아 새로 생성하는 중...`);

return await jiraClient.projectVersions.createVersion({
name: versionName,
Expand Down
2 changes: 1 addition & 1 deletion src/getVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function getVariables() {
host,
email,
apiToken,
issueKeys: issueKeys.split(','),
issueKeys: issueKeys ? issueKeys.split(',') : [],
projectKey,
versionName,
componentName,
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import updateIssues from './updateIssues';
const jiraClient = initJiraClient();
const projectVersion = await getProjectVersion(jiraClient);
if (!projectVersion) {
throw new Error(`🚫 Failed to find or create project version: ${versionName}`);
throw new Error(`🚫 프로젝트 버전(${versionName}) 조회 및 생성 실패!`);
}

const issueKeysToUpdate = !componentName
Expand Down
24 changes: 12 additions & 12 deletions src/releaseProjectVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ export default async function releaseProjectVersion(
) {
const { projectKey } = getVariables();

info(
`${colors.white}⏳ Releasing project version ${projectVersion.name}(${projectVersion.id})...`,
);
info(`${colors.white}⏳ 프로젝트 버전(${projectVersion.name}) 릴리즈 중...`);

await jiraClient.projectVersions.updateVersion({
id: projectVersion.id!,
project: projectKey,
released: true,
releaseDate: dayjs().format('YYYY-MM-DD'),
});
try {
await jiraClient.projectVersions.updateVersion({
id: projectVersion.id!,
project: projectKey,
released: true,
releaseDate: dayjs().format('YYYY-MM-DD'),
});
} catch (error) {
info(`${colors.red}🚫 프로젝트 버전(${projectVersion.name}) 릴리즈 실패!`);
}

info(
`${colors.green}✅ Released project version ${projectVersion.name}(${projectVersion.id}) successfully!`,
);
info(`${colors.green}✅ 프로젝트 버전(${projectVersion.name}) 릴리즈 성공!`);
}
47 changes: 25 additions & 22 deletions src/updateIssues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,39 @@ export default async function updateIssues(jiraClient: Version3Client, issueKeys
const { versionName, doneStatusName } = getVariables();

if (!issueKeys.length) {
info(`${colors.yellow}No issues to update`);
info(`${colors.yellow}업데이트할 이슈가 없습니다!`);
return;
}

info(`${colors.white}Updating related issues...`);
info(`${colors.white}관련 JIRA 이슈를 업데이트하는 중...`);

await Promise.all(
issueKeys.map(async (issueKey) => {
info(`${colors.white} 👉 Updating ${issueKey}...`);

const issue = await jiraClient.issues.getIssue({ issueIdOrKey: issueKey });
const transitions = await jiraClient.issues.getTransitions({ issueIdOrKey: issueKey });
const doneTransition = transitions.transitions?.find((t) =>
t.name?.toLocaleLowerCase()?.includes(doneStatusName.toLocaleLowerCase()),
);
if (!doneTransition) {
return;
info(`${colors.white} 👉 ${issueKey} 업데이트 중...`);
try {
const issue = await jiraClient.issues.getIssue({ issueIdOrKey: issueKey });
const transitions = await jiraClient.issues.getTransitions({ issueIdOrKey: issueKey });
const doneTransition = transitions.transitions?.find((t) =>
t.name?.toLocaleLowerCase()?.includes(doneStatusName.toLocaleLowerCase()),
);
if (!doneTransition) {
return;
}
return await Promise.all([
await jiraClient.issues.doTransition({
issueIdOrKey: issueKey,
transition: { id: doneTransition.id },
}),
await jiraClient.issues.editIssue({
issueIdOrKey: issueKey,
fields: { fixVersions: [...issue.fields.fixVersions, { name: versionName }] },
}),
]);
} catch (error) {
info(`${colors.red} 🚫 ${issueKey} 업데이트 실패!`);
}
return await Promise.all([
await jiraClient.issues.doTransition({
issueIdOrKey: issueKey,
transition: { id: doneTransition.id },
}),
await jiraClient.issues.editIssue({
issueIdOrKey: issueKey,
fields: { fixVersions: [...issue.fields.fixVersions, { name: versionName }] },
}),
]);
}),
);

info(`✅ ${issueKeys.length} issues updated`);
info(`${colors.green}${issueKeys.length}개의 이슈 업데이트 완료!`);
}

0 comments on commit 01ee8a2

Please sign in to comment.