Merge "Add ability to skip change request update"
diff --git a/src/com/mirantis/mk/Git.groovy b/src/com/mirantis/mk/Git.groovy
index 5108cda..1426280 100644
--- a/src/com/mirantis/mk/Git.groovy
+++ b/src/com/mirantis/mk/Git.groovy
@@ -510,9 +510,11 @@
* - status Change request's status to search for
* - changeAuthorEmail Author's email of the change
* - changeAuthorName Author's name of the change
- */
+ * - forceUpdate Whether to update change if no diff between local state and remote
+ */
def updateChangeRequest(Map params) {
def gerrit = new com.mirantis.mk.Gerrit()
+ def common = new com.mirantis.mk.Common()
def commitMessage
def auth = params['gerritAuth']
@@ -526,14 +528,28 @@
def status = params.get('status', 'open')
def changeAuthorEmail = params['changeAuthorEmail']
def changeAuthorName = params['changeAuthorName']
+ def forceUpdate = params.get('forceUpdate', true)
def changeParams = ['owner': auth['USER'], 'status': status, 'project': project, 'branch': branch, 'topic': topic]
- def gerritChange = gerrit.findGerritChange(creds, auth, changeParams)
+ def gerritChange = gerrit.findGerritChange(creds, auth, changeParams, '--current-patch-set')
def changeId = params.get('changeId', '')
def commit
if (gerritChange) {
def jsonChange = readJSON text: gerritChange
changeId = jsonChange['id']
+ if(!forceUpdate){
+ def ref = jsonChange['currentPatchSet']['ref']
+ def res
+ dir(repo){
+ sshagent (credentials: [creds]){
+ res = common.shCmdStatus("git fetch origin ${ref} && git diff --quiet --exit-code FETCH_HEAD")["status"]
+ }
+ }
+ if (res == 0){
+ common.infoMsg("Current patch set ${ref} is up to date, no need to update")
+ return
+ }
+ }
}
commitMessage = genCommitMessage(repo, comment, changeId, change_id_seed)
commitGitChanges(repo, commitMessage, changeAuthorEmail, changeAuthorName, false, false)