blob: 646d31ceb444103f84877fe87085515b4493999e [file] [log] [blame]
Hirthanan Subenderanb8402a12020-02-05 14:11:00 -08001#!/usr/bin/env python3
2# -*- coding: utf-8 -*-"
3#
4# Copyright 2020 The Chromium OS Authors. All rights reserved.
5# Use of this source code is governed by a BSD-style license that can be
6# found in the LICENSE file.
7
8"""Module containing methods interfacing with gerrit.
9
10i.e Create new bugfix change tickets, and reading metadata about a specific change.
11"""
12
13from __future__ import print_function
Hirthanan Subenderanb8402a12020-02-05 14:11:00 -080014import json
15import requests
16
Hirthanan Subenderan00f18042020-02-11 17:24:38 -080017from common import CHROMIUM_REVIEW_BASEURL
Hirthanan Subenderanb8402a12020-02-05 14:11:00 -080018
19
20def get_commit(changeid):
21 """Retrieves current commit message for a change.
22
23 May add some additional information to the fix patch for tracking purposes.
24 i.e attaching a tag
25 """
26 get_commit_endpoint = (f'{CHROMIUM_REVIEW_BASEURL}/changes/{changeid}/'
27 'revisions/current/commit')
28
29 resp = requests.get(get_commit_endpoint)
30 resp_json = json.loads(resp.text[5:])
31
32 return resp_json
33
34
35def get_reviewers(changeid):
36 """Retrieves list of reviewers from gerrit given a chromeos changeid."""
37 list_reviewers_endpoint = (f'{CHROMIUM_REVIEW_BASEURL}/changes/{changeid}/'
38 'reviewers/')
39
40 resp = requests.get(list_reviewers_endpoint)
41 resp_json = json.loads(resp.text[5:])
42
43 return resp_json
44
45
46def get_change(changeid):
47 """Retrieves ChangeInfo from gerrit using its changeid"""
48 get_change_endpoint = (f'{CHROMIUM_REVIEW_BASEURL}/changes/{changeid}/')
49
50 resp = requests.get(get_change_endpoint)
51 resp_json = json.loads(resp.text[5:])
52
53 return resp_json
54
55
56def generate_fix_commit_message(old_changeid):
57 """Generates new commit message for a fix change.
58
59 Use script ./contrib/from_upstream.py to generate new commit msg
60 Commit message should include essential information:
61 i.e:
62 FROMGIT, FROMLIST, ANDROID, CHROMIUM, etc.
63 commit message indiciating what is happening
64 BUG=...
65 TEST=...
66 tag for Fixes: <upstream-sha>
67 """
68 old_commit_msg = get_commit(old_changeid)
69 print(old_commit_msg)
70
71
72def create_gerrit_change(reviewers, commit_msg):
73 """Uses gerrit api to handle creating gerrit change.
74
75 Determines whether a change for a fix has already been created,
76 and avoids duplicate creations.
77
78 May add some additional information to the fix patch for tracking purposes.
79 i.e attaching a tag,
80 """
81
82 # Call gerrit api to create new change if neccessary
83 print('Calling gerrit api', reviewers, commit_msg)