Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ UseProvidedHistory = False
# True - The user is not prompted
UseAutomaticConflictResolution = False

# Optional, defines a prefix for commit-messages, which were linked to an rtc workitem.
# In case you have migrated your workitems to another issue system (like jira/github/bitbucket) by using rtc2jira,
# you can define a prefix for the commit-message, in order that previously linked rtc commits get linked to the new issue system.
#
# Examples:
# In jira: AP- (Project has the key AP and is followed by a dash)
# see https://confluence.atlassian.com/cloud/processing-jira-issues-with-commit-messages-686854819.html for more details)
# On bitbucket/github: #
CommitMessageWorkItemPrefix=
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines and the optionname...


[Miscellaneous]
# Set to true if you want to see which commands are sent to command line
LogShellCommands = False
Expand Down
15 changes: 12 additions & 3 deletions configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def read(configname=None):
ignorefileextensionsproperty = parsedconfig.get(miscsectionname, 'IgnoreFileExtensions', fallback='')
ignorefileextensions = parseignorefileextensionsproperty(ignorefileextensionsproperty)
includecomponentroots = parsedconfig.get(miscsectionname, 'IncludeComponentRoots', fallback="False")
commitmessageprefix = migrationsection.get('CommitMessageWorkItemPrefix', "")

configbuilder = Builder().setuser(user).setpassword(password).setrepourl(repositoryurl).setscmcommand(scmcommand)
configbuilder.setworkspace(workspace).setgitreponame(gitreponame).setrootfolder(os.getcwd())
Expand All @@ -48,7 +49,7 @@ def read(configname=None):
configbuilder.setworkdirectory(workdirectory).setstreamname(streamname).setinitialcomponentbaselines(baselines)
configbuilder.setpreviousstreamname(previousstreamname)
configbuilder.setignorefileextensions(ignorefileextensions)
configbuilder.setincludecomponentroots(includecomponentroots)
configbuilder.setincludecomponentroots(includecomponentroots).setcommitmessageprefix(commitmessageprefix)
global config
config = configbuilder.build()
return config
Expand Down Expand Up @@ -90,6 +91,7 @@ def parseignorefileextensionsproperty(ignorefileextensionsproperty):
ignorefileextensions.append(splittedextension.strip())
return ignorefileextensions


class Builder:
def __init__(self):
self.user = ""
Expand All @@ -111,6 +113,7 @@ def __init__(self):
self.previousstreamname = ""
self.ignorefileextensions = ""
self.includecomponentroots = ""
self.commitmessageprefix = ""

def setuser(self, user):
self.user = user
Expand Down Expand Up @@ -181,6 +184,10 @@ def setincludecomponentroots(self, includecomponentroots):
self.includecomponentroots = self.isenabled(includecomponentroots)
return self

def setcommitmessageprefix(self, commitmessageprefix):
self.commitmessageprefix = commitmessageprefix
return self

@staticmethod
def isenabled(stringwithbooleanexpression):
return stringwithbooleanexpression == "True"
Expand All @@ -190,14 +197,15 @@ def build(self):
self.useexistingworkspace, self.workdirectory, self.initialcomponentbaselines,
self.streamname, self.gitreponame, self.useprovidedhistory,
self.useautomaticconflictresolution, self.clonedgitreponame, self.rootFolder,
self.previousstreamname, self.ignorefileextensions, self.includecomponentroots)
self.previousstreamname, self.ignorefileextensions, self.includecomponentroots,
self.commitmessageprefix)


class ConfigObject:
def __init__(self, user, password, repourl, scmcommand, workspace, useexistingworkspace, workdirectory,
initialcomponentbaselines, streamname, gitreponame, useprovidedhistory,
useautomaticconflictresolution, clonedgitreponame, rootfolder, previousstreamname,
ignorefileextensionsproperty, includecomponentroots):
ignorefileextensionsproperty, includecomponentroots, commitmessageprefix):
self.user = user
self.password = password
self.repo = repourl
Expand All @@ -219,6 +227,7 @@ def __init__(self, user, password, repourl, scmcommand, workspace, useexistingwo
self.previousstreamuuid = ""
self.ignorefileextensions = ignorefileextensionsproperty
self.includecomponentroots = includecomponentroots
self.commitmessageprefix = commitmessageprefix

def getlogpath(self, filename):
if not self.hasCreatedLogFolder:
Expand Down
13 changes: 12 additions & 1 deletion gitFunctions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from datetime import datetime
import re

import shouter
import shell
Expand Down Expand Up @@ -58,6 +59,7 @@ def initialcommit():

class Commiter:
commitcounter = 0
isattachedtoaworkitemregex = re.compile("^\d*:.*-")

@staticmethod
def addandcommit(changeentry):
Expand Down Expand Up @@ -95,10 +97,19 @@ def handle_captitalization_filename_changes():

@staticmethod
def getcommitcommand(changeentry):
comment = Commiter.replacegitcreatingfilesymbol(changeentry.comment)
cleancomment = Commiter.replacegitcreatingfilesymbol(changeentry.comment)
comment = Commiter.getcommentwithprefix(cleancomment)
return "git commit -m %s --date %s --author=%s" \
% (shell.quote(comment), shell.quote(changeentry.date), changeentry.getgitauthor())

@staticmethod
def getcommentwithprefix(comment):
prefix = configuration.get().commitmessageprefix

if prefix and Commiter.isattachedtoaworkitemregex.match(comment):
return prefix + comment
return comment

@staticmethod
def replacegitcreatingfilesymbol(comment):
return Commiter.replacewords(" to ", comment, "-->", "->", ">")
Expand Down
1 change: 1 addition & 0 deletions tests/resources/test_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ PreviousStream = Previousstream
InitialBaseLines = Component1=Baseline1, Component2=Baseline2
UseProvidedHistory = True
UseAutomaticConflictResolution = True
CommitMessageWorkItemPrefix = UP-

[Miscellaneous]
LogShellCommands = True
Expand Down
2 changes: 2 additions & 0 deletions tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def _assertTestConfig(self, config):
self.assertEqual('Baseline2', initialcomponentbaseline.baselinename)
self.assertTrue(config.useprovidedhistory)
self.assertTrue(config.useautomaticconflictresolution)
self.assertEqual("UP-", config.commitmessageprefix)
# [Miscellaneous]
self.assertTrue(shell.logcommands) # directly deviated to shell
ignorefileextensions = config.ignorefileextensions
Expand All @@ -122,6 +123,7 @@ def _assertDefaultConfig(self, config):
self.assertEqual(0, len(config.initialcomponentbaselines))
self.assertFalse(config.useprovidedhistory)
self.assertFalse(config.useautomaticconflictresolution)
self.assertEqual("", config.commitmessageprefix)
# [Miscellaneous]
self.assertFalse(shell.logcommands) # directly deviated to shell
self.assertEqual(0, len(config.ignorefileextensions))
Expand Down
24 changes: 24 additions & 0 deletions tests/test_gitFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,30 @@ def test_checkbranchname_unquoted_expect_invalid(self):
with testhelper.createrepo(folderprefix="gitfunctionstestcase_"):
self.assertEqual(False, Commiter.checkbranchname("master pflaster"), "master pflaster should not be a valid branch name")

def test_getcommentwithprefix_enabled_commitisattached_shouldreturnwithprefix(self):
prefix = "APREFIX-"
configuration.config = Builder().setcommitmessageprefix(prefix)
comment = "1337: Upgrade to Wildfly - A comment"
expectedcomment = prefix + comment
self.assertEqual(expectedcomment, Commiter.getcommentwithprefix(comment))

def test_getcommentwithprefix_enabled_commitisattached_containsspecialchars_shouldreturnwithprefix(self):
prefix = "PR-"
configuration.config = Builder().setcommitmessageprefix(prefix)
comment = "1338: VAT: VAT-Conditions defined with 0 % and 0 amount - reverse"
expectedcomment = prefix + comment
self.assertEqual(expectedcomment, Commiter.getcommentwithprefix(comment))

def test_getcommentwithprefix_disabled_commitisattached_shouldreturncommentwithoutprefix(self):
configuration.config = Builder().setcommitmessageprefix("")
comment = "1337: Upgrade to Wildfly - A comment"
self.assertEqual(comment, Commiter.getcommentwithprefix(comment))

def test_getcommentwithprefix_enabled_commitisnotattachedtoanworkitem_shouldreturncommentwithoutprefix(self):
configuration.config = Builder().setcommitmessageprefix("PR-")
comment = "US1337: Fix some problems"
self.assertEqual(comment, Commiter.getcommentwithprefix(comment))

def simulateCreationAndRenameInGitRepo(self, originalfilename, newfilename):
open(originalfilename, 'a').close() # create file
Initializer.initialcommit()
Expand Down