반응형

기본적으로, gitlab의 issue에서 merge request를 생성할 때, 브랜치 명은 다음 규칙을 따른다.

{이슈번호}-{이슈명 축약}

이슈명의 경우, 한글로 작성할 경우 {이슈번호}- 로만 표기되는 경우도 잦고, 이슈만을 위한 branch를 찾기도 번거롭다.

따라서, branch명의 템플릿을 변경하는 방법에 대해 작성하고자 한다.

Merge Request branch name template 변경

embedded/service/gitlab-rails/app/models/issue.rb 파일의 to_branch_name 함수 변경

변경전

  def to_branch_name
    if self.confidential?
      "#{iid}-confidential-issue"
    else
      self.class.to_branch_name(iid, title)
    end
  end

변경후

  def to_branch_name
    if self.confidential?
      "#{iid}-confidential-issue"
    else
      #self.class.to_branch_name(iid, title)
      "issue/#{iid}"
    end
  end
이전버전

변경전

  def to_branch_name
    if self.confidential?
      "#{iid}-confidential-issue"
    else
      branch_name = "#{iid}-#{title.parameterize}" # 변경지점

      if branch_name.length > 100
        truncated_string = branch_name[0, 100]
        # Delete everything dangling after the last hyphen so as not to risk
        # existence of unintended words in the branch name due to mid-word split.
        branch_name = truncated_string[0, truncated_string.rindex("-")]
      end

      branch_name
    end
  end

변경후

  def to_branch_name
    if self.confidential?
      "#{iid}-confidential-issue"
    else
      branch_name = "issue/#{iid}"

      if branch_name.length > 100
        truncated_string = branch_name[0, 100]
        # Delete everything dangling after the last hyphen so as not to risk
        # existence of unintended words in the branch name due to mid-word split.
        branch_name = truncated_string[0, truncated_string.rindex("-")]
      end

      branch_name
    end
  end

변경 결과

변경 및 gitlab 서버를 재기동 후에 Create merge request의 drop down 메뉴를 열어보면 설정된 값으로 변환되어 있음을 확인할 수 있다.

기타 변수들을 잘 활용할 경우 issue/{이슈번호} 템플릿 외의 다른 템플릿을 적용하여 사용할 수 있을것으로 보인다.

gitlab을 업데이트 할 경우, 해당 변경 사항이 원상복귀 될 것으로 보이는데, 해당 부분은 차기 버전에서 설정으로 변경 가능하도록 적용해줬으면 한다.

반응형

댓글을 달아 주세요