blob: 150e237606211419b32ebb21b66357b167c39949 [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
14
15import json
16import requests
17
18from config import CHROMIUM_REVIEW_BASEURL
19
20
21def get_commit(changeid):
22 """Retrieves current commit message for a change.
23
24 May add some additional information to the fix patch for tracking purposes.
25 i.e attaching a tag
26 """
27 get_commit_endpoint = (f'{CHROMIUM_REVIEW_BASEURL}/changes/{changeid}/'
28 'revisions/current/commit')
29
30 resp = requests.get(get_commit_endpoint)
31 resp_json = json.loads(resp.text[5:])
32
33 return resp_json
34
35
36def get_reviewers(changeid):
37 """Retrieves list of reviewers from gerrit given a chromeos changeid."""
38 list_reviewers_endpoint = (f'{CHROMIUM_REVIEW_BASEURL}/changes/{changeid}/'
39 'reviewers/')
40
41 resp = requests.get(list_reviewers_endpoint)
42 resp_json = json.loads(resp.text[5:])
43
44 return resp_json
45
46
47def get_change(changeid):
48 """Retrieves ChangeInfo from gerrit using its changeid"""
49 get_change_endpoint = (f'{CHROMIUM_REVIEW_BASEURL}/changes/{changeid}/')
50
51 resp = requests.get(get_change_endpoint)
52 resp_json = json.loads(resp.text[5:])
53
54 return resp_json
55
56
57def generate_fix_commit_message(old_changeid):
58 """Generates new commit message for a fix change.
59
60 Use script ./contrib/from_upstream.py to generate new commit msg
61 Commit message should include essential information:
62 i.e:
63 FROMGIT, FROMLIST, ANDROID, CHROMIUM, etc.
64 commit message indiciating what is happening
65 BUG=...
66 TEST=...
67 tag for Fixes: <upstream-sha>
68 """
69 old_commit_msg = get_commit(old_changeid)
70 print(old_commit_msg)
71
72
73def create_gerrit_change(reviewers, commit_msg):
74 """Uses gerrit api to handle creating gerrit change.
75
76 Determines whether a change for a fix has already been created,
77 and avoids duplicate creations.
78
79 May add some additional information to the fix patch for tracking purposes.
80 i.e attaching a tag,
81 """
82
83 # Call gerrit api to create new change if neccessary
84 print('Calling gerrit api', reviewers, commit_msg)