Esempio n. 1
0
 def PUSH(self, sRepoUrl):
     sChangeId = gerrit.getChangeId()
     if not sChangeId:
         raise FatalError("Unable to extract Change-Id")
     sProject = gerrit.getProjectName()
     oRepoData = self.getRepoData()
     sLocalCommit = git.getLastCommit()
     try:
         dChangeData = self.getApiClient().getChangeData(
             sChangeId, sProject, lAdditionalData=["CURRENT_REVISION"])
     except requests.HTTPError as e:
         if e.response.status_code != 404:
             raise
     else:
         sRemoteCommit = dChangeData["current_revision"]
         sLastPushedCommit = oRepoData.getLastPushedCommit(
             sProject, sChangeId)
         if sRemoteCommit == sLocalCommit:
             warning("No new changes")
             return
         elif sRemoteCommit != sLastPushedCommit:
             warning("You are about to overwrite unknown changes.")
             sInput = input("Continue? (y/n): ")
             if sInput != "y":
                 raise FatalError("Operation aborted")
     print("Pushing changes to %s" % sRepoUrl)
     gerrit.push()
     oRepoData.setLastPushedCommit(sProject, sChangeId, sLocalCommit)
     self.saveRepoData(oRepoData)
Esempio n. 2
0
 def push(self):
     self.runRepo(["push"])
     lChangeNumbers = []
     for sProjectFolder, sProjectName in self.dProjectFolders.items():
         with changeWorkingDir(sProjectFolder):
             dJson = self.oApiClient.getChangeData(gerrit.getChangeId(),
                                                   sProjectName)
             lChangeNumbers.append(dJson["_number"])
     return lChangeNumbers
Esempio n. 3
0
 def repoDownloadTestSetup(self):
     self.runRepo(["start", "topic_2"])
     self.runRepo(["start", "topic_1"])
     self.createCommit(sId="1")
     self.push()
     self.createCommit(sId="1", bAmend=True)
     iChangeNumber = self.push()[0]
     with changeWorkingDir(next(iter(self.dProjectFolders))):
         sChangeId = gerrit.getChangeId()
     self.runRepo(["switch", "topic_2"])
     self.createCommit(sId="2")
     return iChangeNumber, sChangeId
Esempio n. 4
0
    def test_getChange(self):
        self.createCommit()
        self.push()

        for sProjectFolder, sProjectName in self.dProjectFolders.items():
            with changeWorkingDir(sProjectFolder):
                sChangeId = gerrit.getChangeId()
                dChange = self.oApiClient.getChangeData(
                    sChangeId, sProjectName)

                assert dChange is not None
                assert dChange["id"] == "%s~master~%s" % (quote(
                    sProjectName, safe=""), sChangeId)
                assert dChange["project"] == sProjectName
                assert dChange["branch"] == "master"
                assert dChange["change_id"] == sChangeId
                assert dChange["status"] == "NEW"
Esempio n. 5
0
 def PULL(self, sRepoUrl):
     sChangeId = gerrit.getChangeId()
     if not sChangeId:
         raise FatalError("Unable to extract Change-Id")
     sProject = gerrit.getProjectName()
     try:
         dChangeData = self.getApiClient().getChangeData(
             sChangeId, sProject, lAdditionalData=["ALL_REVISIONS"])
     except requests.HTTPError as e:
         if e.response.status_code == 404:
             warning("No remote patch")
             return
         raise e
     sRemoteCommit = dChangeData["current_revision"]
     sLocalCommit = git.getLastCommit()
     sLastPushedCommit = self.getRepoData().getLastPushedCommit(
         sProject, sChangeId)
     if sRemoteCommit == sLocalCommit:
         print("Already up-to-date.")
         return
     elif sRemoteCommit == sLastPushedCommit:
         print("You are ahead of Gerrit.")
         return
     elif sLocalCommit in dChangeData["revisions"]:
         print("Pulling changes from %s" % sRepoUrl)
         sBranch = git.getCurrentBranch()
         dFetchData = dChangeData["revisions"][sRemoteCommit]["fetch"][
             "ssh"]
         subprocess.run(
             ["git", "fetch", dFetchData["url"], dFetchData["ref"]],
             check=True)
         subprocess.run(["git", "checkout", "FETCH_HEAD"], check=True)
         if sBranch:
             subprocess.run(["git", "branch", "-D", sBranch], check=True)
             subprocess.run(["git", "checkout", "-b", sBranch], check=True)
     else:
         raise FatalError("You have local commits unknown to Gerrit")
Esempio n. 6
0
 def createChange(self, sId="1", bAmend=False):
     dCommits = {}
     for sProjectFolder, sProjectName in self.dProjectFolders.items():
         with changeWorkingDir(sProjectFolder):
             if bAmend:
                 sChangeId = gerrit.getChangeId()
                 dJson = {"message": "Amended test commit (%s)" % sId}
                 self.oApiClient.put("changes/%s~master~%s/message" %
                                     (quote_plus(sProjectName), sChangeId),
                                     json=dJson)
             else:
                 dJson = {
                     "project": sProjectName,
                     "branch": "master",
                     "subject": "Test commit (%s)" % sId
                 }
                 sChangeId = self.oApiClient.post("changes/",
                                                  json=dJson)["change_id"]
             dJson = self.oApiClient.getChangeData(
                 sChangeId,
                 sProjectName,
                 lAdditionalData=["CURRENT_REVISION"])
             dCommits[sProjectName] = dJson["current_revision"]
     return dCommits