¿Alguien tiene un enlace de compromiso de git que pueda usar que asegure que aparezca un número de problema de JIRA en el mensaje de registro? No tengo experiencia en manejar JIRA desde un gancho de cometer git, por lo que cualquier ayuda sería apreciada, ¡aún más si se trata de una fuente de trabajo!Gancho de compromiso de validación de código JIRA para 'git'
Respuesta
primer lugar, hacer el ejecutable gancho:
chmod a+x .git/hooks/commit-msg
anexar los siguientes líneas, sustituyendo proyecto con el código de su proyecto.
test "" != "$(grep 'PROJECT-' "$1")" || {
echo >&2 "ERROR: Commit message is missing Jira issue number."
exit 1
}
Ops, nunca utilicé git pero un amigo creó SVN-Hooks, un marco para crear ganchos Subversion. Fue codificado en Perl. Tal vez esto ayuda en cualquier way.Take una mirada en ella hay:
http://code.google.com/p/svn-hooks/source/browse/trunk/t/02-jiraacceptance.t
Y si es necesario llamar por teléfono, lo antes posible estaremos encantados de ayudarle.
Escribiría un enlace de confirmación que asegure que algo que parece aparece como un número de problema JIRA en algún lugar del mensaje de confirmación. Para hacer eso, un simple coincidencia de expresiones regulares lo haría:
/[A-Z0-9]+-\d+/
Si lo desea, para errata-protección adicional se puede asegurar que la primera parte coincide con alguna de identificación del proyecto que ha creado en JIRA:
/(ABC|XYZ|PONIES)-\d+/
me parece que hay poco valor para tratar de asegurarse de que el número parte que hace referencia a un número de emisión válidos. En realidad, no hay forma de determinar si el usuario ingresó el número de problema correcto (incluso si logra limitarlo a problemas abiertos, el usuario aún podría ingresar un número de asunto abierto no relacionado). Se debe esperar que los usuarios tengan cuidado al momento de asignar el código.
#!/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
Parece que esto es de http://foodforsamurai.com/post/483440483/git-to-jira – dave1010
- 1. Número de problema de Jira en el mensaje de compromiso de git
- 2. Problema de cierre de Jira a través de compromiso de Git
- 3. fecha de compromiso de Git
- 4. Git personalización de gancho global
- 5. gancho de pre-recepción GIT
- 6. Gancho precomprometido/compartido de Git
- 7. Gancho de precompilación condicional controlado desde la línea de comando para GIT: ¿Es posible?
- 8. Cómo creo una plantilla de mensaje de compromiso de SVN y un gancho para verificar
- 9. Git pre-recepción gancho
- 10. Git: recuperar compromiso específico
- 11. ¿Hay algún gancho git para tirar?
- 12. git, Heroku: gancho de pre-recepción rechazado
- 13. Git gancho pre-commit: obtener la lista de archivos cambiados
- 14. Git gancho: habilitar eco comandos
- 15. git ¿puedo acelerar el compromiso?
- 16. ¿Cómo se relaciona Jira con git?
- 17. Empujar sin compromiso en Mercurial o Git
- 18. Gancho de cierre para rieles
- 19. Ir a svn: Agregar fecha de compromiso para registrar mensajes
- 20. Git - Preservar el trabajo sin compromiso
- 21. Obtener los padres de un compromiso de fusión en git
- 22. Gancho de precompilación de Git: Archivos modificados/agregados
- 23. Git: ¿Cómo clonar el primer compromiso?
- 24. El gancho post-recepción Git no funciona
- 25. ganchos git: ¿hay un gancho clon?
- 26. Enlace simbólico a un gancho en git
- 27. Gancho precommitido para JSLint en Mercurial y Git
- 28. ¿Edita el compromiso raíz en Git?
- 29. gancho git-clone y post-checkout
- 30. ¿Git comete un mensaje de compromiso y nada más?
Para comprobar si hay múltiples proyectos y para asegurar que hay un problema de identificación, use: grep -E '(PRJA | PRJB) - [[: digit:]] +' – Martin
¿Es posible hacer esta validación por parte de Atlassian? Para evitar tener que decirle a cada uno de los tipos no técnicos del equipo cómo hacer esto. –