0

I am working on Gerrit Code review tool. I want to fetch the data about the change with Gerrit rest api. I am able to get the other content but not able to fetch the files changed in the review. code for getting the details of the change is:

gerrit_username = os.environ.get('GERRIT_USERNAME')
gerrit_password = os.environ.get('GERRIT_PASSWORD')
gerrit_url = os.environ.get('GERRIT_URL')

auth = HTTPBasicAuth(self.gerrit_username, self.gerrit_password)
rest = GerritRestAPI(url=self.gerrit_url, auth=auth)

review_details = rest.get('changes/' + self.review_id + '/detail/q?o=CURRENT_REVISION&o=CURRENT_COMMIT', headers={'Content-Type': 'application/json'})

This code gives me a dictionary containing info like id, project, owner name etc but not file name.

Is there any different mechanism to get the file name?

1 Answer 1

0

Try adding the CURRENT_FILES parameter in the query as per documentation.

See in the following example the file names in the file section of the JSON response:

> curl "https://review.gerrithub.io/changes/?q=I79609cdaf636dc712b3a1e9cffb25aef98f69123&o=CURRENT_FILES&o=CURRENT_REVISION"
)]}'
[
  {
    "id": "NexellCorp%2Fandroid_platform_packages_apps_Car_Launcher~pie-dev~I79609cdaf636dc712b3a1e9cffb25aef98f69123",
    "project": "NexellCorp/android_platform_packages_apps_Car_Launcher",
    "branch": "pie-dev",
    "hashtags": [],
    "change_id": "I79609cdaf636dc712b3a1e9cffb25aef98f69123",
    "subject": "Car Launcher: fix for Car Launcher UI",
    "status": "NEW",
    "created": "2020-04-08 10:52:36.000000000",
    "updated": "2020-04-08 10:53:49.000000000",
    "submit_type": "REBASE_ALWAYS",
    "mergeable": true,
    "insertions": 0,
    "deletions": 1,
    "total_comment_count": 0,
    "unresolved_comment_count": 0,
    "has_review_started": true,
    "_number": 489084,
    "owner": {
      "_account_id": 1017471
    },
    "current_revision": "a0cfbc22500e0d15257fc13e483bacc5104ec000",
    "revisions": {
      "a0cfbc22500e0d15257fc13e483bacc5104ec000": {
        "kind": "REWORK",
        "_number": 1,
        "created": "2020-04-08 10:52:36.000000000",
        "uploader": {
          "_account_id": 1017471
        },
        "ref": "refs/changes/84/489084/1",
        "fetch": {
          "anonymous http": {
            "url": "https://review.gerrithub.io/NexellCorp/android_platform_packages_apps_Car_Launcher",
            "ref": "refs/changes/84/489084/1"
          }
        },
        "files": {
          "AndroidManifestQ.xml": {
            "lines_deleted": 1,
            "size_delta": -39,
            "size": 2659
          }
        }
      }
    },
    "requirements": []
  }
]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.