Skip to content

Commit

Permalink
- take username always from git global conf
Browse files Browse the repository at this point in the history
- removed debug output
- add title line back
  • Loading branch information
raymond.schmidt committed Mar 10, 2016
1 parent a98bca6 commit 0001859
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions jiraGitHook/jiraGitHook.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def build_commit_json(self, message):
return json.dumps({"body": message})

def get_username(self, g):
email = g.config('--get','user.name')
email = g.config('--global', '--get', 'user.name')

return email

Expand Down Expand Up @@ -90,10 +90,10 @@ def get_commit_message_body(self, g):
def get_commit_hash(self, g):
return g.log('-1', '--pretty=%H')

def create_jira_message(self, g, gitlab_url, commit_hash, commit_message_body):
return "%s \n\n%s/commit/%s" % (commit_message_body, gitlab_url, commit_hash)
def create_jira_message(self, g, gitlab_url, commit_hash, commit_subject, commit_message_body):
return "%s\n\n%s \n\n%s/commit/%s" % (commit_subject, commit_message_body, gitlab_url, commit_hash)

def git_hook(self, subject = None):
def git_hook(self, subject = None, do_debug = None):
g = git.Git('.')

if not subject:
Expand All @@ -120,10 +120,12 @@ def git_hook(self, subject = None):
paswd = getpass.getpass('password: ')
auth_string = self.get_auth(username, paswd)
commit_hash = self.get_commit_hash(g)
message = self.create_jira_message(g, gitlab_url, commit_hash, commit_message_body)
message = self.create_jira_message(g, gitlab_url, commit_hash, subject, commit_message_body)
prepared_request = self.prepare_request(jira_url, message, auth_string)
# debug
print (self.pretty_print_POST(prepared_request))
if do_debug:
print ('\nusername: %s' % (username))
print (self.pretty_print_POST(prepared_request))
return self.send_commit_message_to_jira(prepared_request)

return ("no ticket id found!")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='0.0.4',
version='0.0.5',

description='commit message will send to jira as comment',
long_description='''
Expand Down
4 changes: 2 additions & 2 deletions tests/testJiraGitHook.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def test_prepared_request(self):
def test_create_jira_message(self):
'http://git.votum-media.net/bio/bio-circle/commit/4e63307c35eaa0288d820be9dc2b5f0157435579'
jiraGitHook = JiraGitHook()
jira_message = jiraGitHook.create_jira_message(self.g, 'http://git.me/project','4e63307c35eaa0288d820be9dc2b5f0157435579', 'the message')
jira_message = jiraGitHook.create_jira_message(self.g, 'http://git.me/project','4e63307c35eaa0288d820be9dc2b5f0157435579', 'some ticket BBB-342', 'the message')

self.assertEquals(jira_message,
"the message \n\nhttp://git.me/project/commit/4e63307c35eaa0288d820be9dc2b5f0157435579")
"some ticket BBB-342\n\nthe message \n\nhttp://git.me/project/commit/4e63307c35eaa0288d820be9dc2b5f0157435579")



Expand Down

0 comments on commit 0001859

Please sign in to comment.