【问题标题】:Gerrit Code Review - Retrieve the file names from the changeGerrit Code Review - 从更改中检索文件名
【发布时间】:2020-04-08 19:04:37
【问题描述】:

我正在开发 Gerrit 代码审查工具。我想使用 Gerrit rest api 获取有关更改的数据。 我能够获取其他内容,但无法获取评论中更改的文件。 获取更改详情的代码是:

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'})

此代码为我提供了一个字典,其中包含 id、项目、所有者名称等信息,但不包含文件名。

是否有任何不同的机制来获取文件名?

【问题讨论】:

    标签: python gerrit


    【解决方案1】:

    尝试按照documentation在查询中添加CURRENT_FILES参数。

    在以下示例中查看 JSON 响应的 file 部分中的文件名:

    > 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": []
      }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-01-22
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      相关资源
      最近更新 更多