blob: fbeaa6401798ee132e82d1c8c99cc3b09321f66e [file] [log] [blame]
Andrew Bonventre89499442016-02-01 13:42:02 -08001<!--
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04002@license
Andrew Bonventre89499442016-02-01 13:42:02 -08003Copyright (C) 2016 The Android Open Source Project
4
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
8
9http://www.apache.org/licenses/LICENSE-2.0
10
11Unless required by applicable law or agreed to in writing, software
12distributed under the License is distributed on an "AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14See the License for the specific language governing permissions and
15limitations under the License.
16-->
Ole Rehmsen31640742019-05-16 11:24:47 +020017<link rel="import" href="/bower_components/polymer/polymer.html">
Paladox none8b0d0462017-03-31 14:37:00 +000018<link rel="import" href="../base-url-behavior/base-url-behavior.html">
Andrew Bonventre89499442016-02-01 13:42:02 -080019<script>
20(function(window) {
21 'use strict';
22
Becky Siegel0cac1762017-08-09 15:56:45 -070023 window.Gerrit = window.Gerrit || {};
24
Logan Hanksc11e5a72016-06-15 12:21:38 -070025 /** @polymerBehavior Gerrit.RESTClientBehavior */
Becky Siegel0cac1762017-08-09 15:56:45 -070026 Gerrit.RESTClientBehavior = [{
Andrew Bonventre89499442016-02-01 13:42:02 -080027 ChangeDiffType: {
28 ADDED: 'ADDED',
29 COPIED: 'COPIED',
30 DELETED: 'DELETED',
31 MODIFIED: 'MODIFIED',
32 RENAMED: 'RENAMED',
33 REWRITE: 'REWRITE',
34 },
35
36 ChangeStatus: {
Andrew Bonventre89499442016-02-01 13:42:02 -080037 ABANDONED: 'ABANDONED',
Viktar Donich7bb03b82016-08-08 12:41:50 -070038 MERGED: 'MERGED',
39 NEW: 'NEW',
Andrew Bonventre89499442016-02-01 13:42:02 -080040 },
41
42 // Must be kept in sync with the ListChangesOption enum and protobuf.
43 ListChangesOption: {
44 LABELS: 0,
45 DETAILED_LABELS: 8,
46
47 // Return information on the current patch set of the change.
48 CURRENT_REVISION: 1,
49 ALL_REVISIONS: 2,
50
51 // If revisions are included, parse the commit object.
52 CURRENT_COMMIT: 3,
53 ALL_COMMITS: 4,
54
55 // If a patch set is included, include the files of the patch set.
56 CURRENT_FILES: 5,
57 ALL_FILES: 6,
58
59 // If accounts are included, include detailed account info.
60 DETAILED_ACCOUNTS: 7,
61
62 // Include messages associated with the change.
63 MESSAGES: 9,
64
65 // Include allowed actions client could perform.
66 CURRENT_ACTIONS: 10,
67
68 // Set the reviewed boolean for the caller.
69 REVIEWED: 11,
70
71 // Include download commands for the caller.
72 DOWNLOAD_COMMANDS: 13,
73
74 // Include patch set weblinks.
75 WEB_LINKS: 14,
76
77 // Include consistency check results.
78 CHECK: 15,
79
80 // Include allowed change actions client could perform.
81 CHANGE_ACTIONS: 16,
82
83 // Include a copy of commit messages including review footers.
84 COMMIT_FOOTERS: 17,
85
86 // Include push certificate information along with any patch sets.
Ravi Mistry6fca1a82016-10-05 14:19:12 -040087 PUSH_CERTIFICATES: 18,
88
89 // Include change's reviewer updates.
90 REVIEWER_UPDATES: 19,
91
92 // Set the submittable boolean.
Kasper Nilsson8ab1f502017-05-14 18:10:42 -070093 SUBMITTABLE: 20,
Wyatt Allen96b16e72018-01-18 09:45:44 -080094
95 // If tracking ids are included, include detailed tracking ids info.
96 TRACKING_IDS: 21,
97
98 // Skip mergeability data.
99 SKIP_MERGEABLE: 22,
Gal Paikin17b70482019-07-12 13:46:11 +0200100
101 /**
102 * Skip diffstat computation that compute the insertions field (number of lines inserted) and
103 * deletions field (number of lines deleted)
104 */
105 SKIP_DIFFSTAT: 23,
Andrew Bonventre89499442016-02-01 13:42:02 -0800106 },
107
Kasper Nilsson8ab1f502017-05-14 18:10:42 -0700108 listChangesOptionsToHex(...args) {
109 let v = 0;
110 for (let i = 0; i < args.length; i++) {
111 v |= 1 << args[i];
Andrew Bonventre89499442016-02-01 13:42:02 -0800112 }
113 return v.toString(16);
114 },
115
Becky Siegel8d92d532017-08-11 16:32:47 -0700116 /**
117 * @return {string}
118 */
Logan Hanks90b4dc42018-10-30 09:40:22 -0700119 changeBaseURL(project, changeNum, patchNum) {
120 let v = this.getBaseUrl() + '/changes/' +
121 encodeURIComponent(project) + '~' + changeNum;
Andrew Bonventre89499442016-02-01 13:42:02 -0800122 if (patchNum) {
123 v += '/revisions/' + patchNum;
124 }
125 return v;
126 },
David Ostrovskye8771402016-02-13 12:23:53 +0100127
Kasper Nilsson8ab1f502017-05-14 18:10:42 -0700128 changePath(changeNum) {
Paladox none8b0d0462017-03-31 14:37:00 +0000129 return this.getBaseUrl() + '/c/' + changeNum;
David Ostrovskye8771402016-02-13 12:23:53 +0100130 },
Urs Wolfer6ed09582016-04-07 21:40:39 +0200131
Paladox none7dca1282019-07-09 22:45:44 +0000132 changeIsOpen(change) {
133 return change && change.status === this.ChangeStatus.NEW;
Urs Wolfer6ed09582016-04-07 21:40:39 +0200134 },
Viktar Donich7bb03b82016-08-08 12:41:50 -0700135
Becky Siegel020e1be2017-12-22 12:57:11 -0800136 /**
137 * @param {!Object} change
138 * @param {!Object=} opt_options
139 *
140 * @return {!Array}
141 */
142 changeStatuses(change, opt_options) {
Kasper Nilsson66c5d9a2017-07-20 12:50:22 -0700143 const states = [];
Viktar Donich7bb03b82016-08-08 12:41:50 -0700144 if (change.status === this.ChangeStatus.MERGED) {
Kasper Nilsson66c5d9a2017-07-20 12:50:22 -0700145 states.push('Merged');
146 } else if (change.status === this.ChangeStatus.ABANDONED) {
147 states.push('Abandoned');
Wyatt Allen96b16e72018-01-18 09:45:44 -0800148 } else if (change.mergeable === false ||
149 (opt_options && opt_options.mergeable === false)) {
Kasper Nilssonf73f8cf2017-07-21 16:56:19 -0700150 // 'mergeable' prop may not always exist (@see Issue 6819)
Kasper Nilsson66c5d9a2017-07-20 12:50:22 -0700151 states.push('Merge Conflict');
Viktar Donich7bb03b82016-08-08 12:41:50 -0700152 }
Kasper Nilsson66c5d9a2017-07-20 12:50:22 -0700153 if (change.work_in_progress) { states.push('WIP'); }
154 if (change.is_private) { states.push('Private'); }
Becky Siegel020e1be2017-12-22 12:57:11 -0800155
156 // If there are any pre-defined statuses, only return those. Otherwise,
157 // will determine the derived status.
158 if (states.length || !opt_options) { return states; }
159
160 // If no missing requirements, either active or ready to submit.
Wyatt Allen41816a32018-04-13 10:56:25 -0700161 if (change.submittable && opt_options.submitEnabled) {
Becky Siegel020e1be2017-12-22 12:57:11 -0800162 states.push('Ready to submit');
163 } else {
164 // Otherwise it is active.
165 states.push('Active');
166 }
Becky Siegel9b03dd22017-10-26 14:57:32 -0700167 return states;
168 },
169
Becky Siegel020e1be2017-12-22 12:57:11 -0800170 /**
171 * @param {!Object} change
172 * @return {String}
173 */
Becky Siegel9b03dd22017-10-26 14:57:32 -0700174 changeStatusString(change) {
175 return this.changeStatuses(change).join(', ');
Viktar Donich7bb03b82016-08-08 12:41:50 -0700176 },
Becky Siegel0cac1762017-08-09 15:56:45 -0700177 },
Dmitrii Filippovb82003c2019-11-05 17:02:59 +0100178 Gerrit.BaseUrlBehavior,
Paladox none8b0d0462017-03-31 14:37:00 +0000179 ];
Andrew Bonventre89499442016-02-01 13:42:02 -0800180})(window);
181</script>