Skip to content

Commit

Permalink
Merge pull request #1379 from sinProject-Inc/1365-update-create_git_b…
Browse files Browse the repository at this point in the history
…ranch.ts

Docs: Update create_git_branch.ts #1365
  • Loading branch information
sinproject-iwasaki authored Sep 8, 2023
2 parents 0baafa1 + cf5bad6 commit d0f6543
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lib/git/create_git_branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,23 @@ export class CreateGitBranch {

private _generate_branch_name(issue_string: string): string {
// Issue名と番号を抽出
const issue_parts = issue_string.match(/(.*)(#\d+)/)
const issue_parts = RegExp(/^(.*?)(#\d+)$/).exec(issue_string)

if (!issue_parts) {
throw new Error('Invalid issue string format')
}

const issue_number = issue_parts[2].substring(1)
const issue_name = issue_parts[1].replaceAll(/[^a-zA-Z0-9- .]/g, '').trim()
const replaced_issue_name = issue_parts[1].replaceAll(/[/_]/g, '-').trim()
const issue_name = replaced_issue_name.replaceAll(/[^a-zA-Z0-9- .]/g, '').trim()
const kebab_case_issue_name = this._to_kebab_case(issue_name)

// Issue番号とkebab-case形式のIssue名を組み合わせてブランチ名を生成
const branch_name = `${issue_number}-${kebab_case_issue_name}`

// eslint-disable-next-line no-console
// console.info(branch_name)

return branch_name
}
private async _create_git_branch(branch_name: string): Promise<void> {
Expand All @@ -32,7 +37,7 @@ export class CreateGitBranch {
const { stdout, stderr } = await exec(`git checkout -b ${branch_name}`)

// eslint-disable-next-line no-console
console.log(stderr ? stderr : stdout)
console.log(stderr || stdout)
} catch (error) {
// eslint-disable-next-line no-console
console.warn((error as Error).message)
Expand Down

0 comments on commit d0f6543

Please sign in to comment.