누구나 git commit 훅을 사용하여 체크인 메시지에 JIRA 문제 번호가 나타나는지 확인할 수 있습니까? 나는 git commit hook에서 JIRA를 구동시키는 경험이 없기 때문에 어떤 도움을 주시면 감사하겠습니다.'git'에 대한 JIRA 코드 검증 커밋 훅
답변
첫째, 후크 실행합니다
chmod a+x .git/hooks/commit-msg
프로젝트의 코드와 프로젝트를 대체하여 다음 줄을 추가합니다.
는test "" != "$(grep 'PROJECT-' "$1")" || {
echo >&2 "ERROR: Commit message is missing Jira issue number."
exit 1
}
작전, 전 아직 사용하지는 않았지만 친구는 Subversion 훅을 만들기위한 프레임 워크 인 SVN-Hooks를 만들었습니다. perl로 코딩되어있다.
http://code.google.com/p/svn-hooks/source/browse/trunk/t/02-jiraacceptance.t
을 그리고 당신이 우리를 문의해야하는 경우, 최대한 빨리 우리는 기꺼이 도와거야 : 어쩌면 어떤이 도움이 거기에 모습을 way.Take.
이 인 것 같이 커밋 메시지의 어딘가에 JIRA 발행 번호가 표시되도록 커밋 후크를 작성합니다. 이를 위해 간단한 정규 표현식 매치 그것을 할 것입니다 : 당신이 원하는 경우
/[A-Z0-9]+-\d+/
는, 여분의 오타 방지를위한 첫 번째 부분은 당신이 JIRA에서 설정 한 일부 프로젝트 식별자와 일치하는지 확인 할 수 있습니다
를/(ABC|XYZ|PONIES)-\d+/
는 그의 수 부분은 유효한 문제의 수를 의미 있는지 확인하려고 거의 값이 찾을 수 있습니다. 실제로 사용자가 올바른 이슈 번호를 입력했는지 여부를 판단 할 수있는 방법은 없습니다 (문제를 열어 관리하더라도 사용자가 관련없는 공개 이슈 번호를 입력 할 수 있음). 사용자는 코드를 커밋 할 때주의를 기울여야합니다.
#!/usr/bin/env ruby
#
# Update JIRA with git commit messages
#
# == Usage ==
#
# To update a JIRA issue, prepend the first line of your git commit
# message with the issue key and a colon:
#
# $ git commit -m "GIT-1: Updates something"
#
# A comment will be added to the GIT-1 issue that looks something
# like:
#
# Commit: <Hash>
# Author: Bob Example <[email protected]>
# Date: Mon Jul 14 14:00:00 -0400 2008
#
# GIT-1: Updates something
#
# To change an issue's status, append an action string:
#
# GIT-1 resolved: Updates something
# GIT-1 closed: Finishes this
# GIT-1 reopen: Starting work on this
#
# To update multiple issues, separate them with a comma:
#
# GIT-1, GIT-2: Adds comments to GIT-1 and GIT-2
# GIT-1, GIT-2 resolved: Updates GIT-1 and resolves GIT-2
#
# == Installation ==
#
# To get this working, first install a few gems:
#
# $ gem install soap4r
#
# Now, jira4r, which has to be pulled down from subversion:
#
# $ svn co http://svn.rubyhaus.org/jira4r/trunk jira4r
# $ cd jira4r
# $ gem build jira4r.gemspec
# $ gem install jira4r-*.gem
#
# And finally, grit, a Ruby git library. As of today (July 14, 2008),
# the most updated fork is being maintained by Scott Chacon on github.
# For whatever reason, my attempt to install the gem directly wasn't
# working (doesn't appear to be exposed?), so I cloned and installed
# directly:
#
# $ git clone git://github.com/schacon/grit.git
# $ cd grit
# $ gem build grit.gemspec
# $ gem install grit-*.gem
#
# When the gem gets fixed, it should be a simple:
#
# $ gem sources --add http://gems.github.com
# $ gem install schacon-grit
#
# Now just copy/symlink/move an executable copy of this file into your
# .git/hooks directory (be sure not to overwrite an existing hook):
#
# $ cp jira-post-receive /path/to/repo/.git/hooks/post-receive
#
# And don't forget to update some globals below. Voila. You should
# be in business.
#
# == TODO ==
#
# * Get status changes with comments working.
#
require "rubygems"
require "jira4r/jira_tool"
require "grit"
# Don't forget to set these.
#
# I'd recommend creating a dedicated user in JIRA to execute these
# updates. That user will need permissions to:
#
# * Browse Projects
# * Resolve Issues
# * Close Issues
# * Add Comments
#
# (I think that's comprehensive.)
JIRA_ADDRESS = "http://yourserver.com/jira"
JIRA_PROJECT = "DEMO"
JIRA_USERNAME = "user"
JIRA_PASSWORD = "password"
class JiraPostReceive
def initialize(old_commit, new_commit, ref)
@old_commit = old_commit
@new_commit = new_commit
@ref = ref
@repo = Grit::Repo.new(".")
end
def jira
unless @jira
@jira = Jira4R::JiraTool.new(2, JIRA_ADDRESS)
@jira.logger = Logger.new("/dev/null")
@jira.login(JIRA_USERNAME, JIRA_PASSWORD)
end
@jira
end
def run
unless issues.empty?
jira # Sets up access to Jira4R::V2 constants
issues.each do |issue|
begin
send_comment(issue)
send_new_status(issue) if issue[:new_status]
rescue
next
end
end
end
end
# Adds a comment to the JIRA issue
#
# Unfortunately, all comments originate from the dedicated JIRA
# user that's used to post the comment. It's possible to set a
# different author for the comment, but looking one up via email
# in JIRA doesn't seem possible without giving the user
# administrative rights.
def send_comment(issue)
comment = Jira4R::V2::RemoteComment.new
comment.author = JIRA_USERNAME
comment.body = generate_comment(issue[:commit])
jira.addComment(issue[:key], comment)
end
def send_new_status(issue)
status_string = case issue[:new_status]
when "resolved" then "Resolve Issue"
when "closed" then "Close Issue"
when "reopen" then "Reopen Issue"
end
if status = jira.getAvailableActions(issue[:key]).
find { |a| a.name == status_string }
jira.progressWorkflowAction(issue[:key], status.id.to_s, [])
end
end
def issues
issues = []
issued_commits.each do |commit|
issue_string = commit.short_message.match(/(.*?):/)[1]
issue_string.split(",").each do |snippet|
snippet.strip!
snippet =~ /(#{JIRA_PROJECT}-\d+)\s?(resolved|closed|reopen)?/i
issues << { :key => $1, :new_status => $2, :commit => commit }
end
end
issues
end
def issued_commits
new_commits.select do |commit|
commit.short_message =~ /(#{JIRA_PROJECT}-\d+)(.*):/
end
end
# Fetch commits that are new to the repository
#
# That super-piped git command makes sure that we only update JIRA
# with commits that are new, and haven't been seen in any other
# branches. It's lifted verbatim from the post-receive-email hook
# that's shipped in the git repository --
# contrib/hooks/post-receive-email.
def new_commits
common_cmd = "git rev-parse --not --branches | " +
"grep -v $(git rev-parse #{@ref}) | " +
"git rev-list --stdin "
commit_ids = if branch_created?
`#{common_cmd} #{@new_commit}`.split
elsif branch_updated?
`#{common_cmd} #{@old_commit}..#{@new_commit}`.split
else
[]
end
commit_ids.map { |id| @repo.commit(id) }.reverse
end
def generate_comment(commit)
<<-EOS
Commit: #{commit.id}
Author: #{commit.author.name} <#{commit.author.email}>
Date: #{commit.authored_date}
#{commit.message}
EOS
end
def branch_created?
@ref =~ /refs\/heads/ && @old_commit =~ /^0+$/
end
def branch_updated?
@ref =~ /refs\/heads/ && @old_commit !~ /^0+$/ &&
@new_commit !~ /^0+$/
end
end
old_commit, new_commit, ref = STDIN.gets.split
JiraPostReceive.new(old_commit, new_commit, ref).run
exit 0
다음은 http://foodforsamurai.com/post/483440483/git-to-jira에서 가져온 것입니다. – dave1010
- 1. git에서 커밋 훅 처리하기
- 2. SVN - 코드 형식을 검사하기위한 사전 커밋 훅
- 3. Git Post 커밋 훅 커밋 번호 얻기
- 4. 포스트 커밋 훅 with Trac
- 5. 이미 커밋 된 코드 리비전으로 JIRA 문제를 업데이트하는 방법이 있습니까?
- 6. 커밋 할 때마다 git에 파일을 추가해야합니까?
- 7. git에 대한 액세스 로그
- 8. Git에 대한 대안?
- 9. Git에 안드로이드 "gen"폴더를 커밋 할 수 없습니다.
- 10. 일관성없는 탭 사용으로 파이썬 파일을 거부하는 SVN 사전 커밋 훅
- 11. Git에 기존 소스 코드 폴더 추가
- 12. SVN 허드슨 JIRA interaction
- 13. SharpSvn을 사용하여 사전 커밋 훅 작성하기. svnlook propget이 부족합니까?
- 14. 포스트 커밋 (post-commit) 훅 스크립트는 어디에 두어야하나요?
- 15. 복제본 저장소에 내 Git 사전 커밋 훅 트리거가없는 이유는 무엇입니까?
- 16. TortoiseSVN 클라이언트 미리 커밋 훅 저장소 URL 가져 오기
- 17. 커밋 n에서 git에 파일이 추가되었습니다. 대신에 그것을 추가하여 n-m을 커밋 할 수 있습니까?
- 18. 누구나 코드 커밋시 전자 메일을 보낼 커밋 알림 훅 스크립트가 있습니까?
- 19. CVS/Git에 대한 MMIX 저장소 얻기
- 20. SVN 훅 스크립트 충돌
- 21. tfs에 대한 커밋 모니터
- 22. Git에 지점이없는 파일들
- 23. 특수 문자에 대한 필수 검증
- 24. git에 '소셜'확장이 있습니까? 또는 원격 모니터링 도구?
- 25. JIRA 외부의 JIRA 내보내기 검색 및 엑셀
- 26. git에 문제가 있습니다.
- 27. 오류 코드 -2147483645로 사전 검증 실패
- 28. 커밋 다시 커밋 되돌릴 커밋
- 29. Emacs의 파일 확장자 훅
- 30. Windows 서버의 커밋 전자 메일
여러 프로젝트를 확인하고 문제 아이디 사용이 있는지 확인하기 : GREP -E '(PRJA | PRJB) - [[: 자리 :]] +' – Martin
는하는 것이 가능 Atlassian 측에서이 확인을합니까? 팀에서 비 기술적 인 사람들에게 어떻게하는지 알려주지 않으려면. –