Andrew Bonventre | 8949944 | 2016-02-01 13:42:02 -0800 | [diff] [blame] | 1 | <!-- |
Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 2 | @license |
Andrew Bonventre | 8949944 | 2016-02-01 13:42:02 -0800 | [diff] [blame] | 3 | Copyright (C) 2016 The Android Open Source Project |
| 4 | |
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | you may not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| 8 | |
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, software |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | See the License for the specific language governing permissions and |
| 15 | limitations under the License. |
| 16 | --> |
Ole Rehmsen | 3164074 | 2019-05-16 11:24:47 +0200 | [diff] [blame] | 17 | <link rel="import" href="/bower_components/polymer/polymer.html"> |
Paladox none | 8b0d046 | 2017-03-31 14:37:00 +0000 | [diff] [blame] | 18 | <link rel="import" href="../base-url-behavior/base-url-behavior.html"> |
Andrew Bonventre | 8949944 | 2016-02-01 13:42:02 -0800 | [diff] [blame] | 19 | <script> |
| 20 | (function(window) { |
| 21 | 'use strict'; |
| 22 | |
Becky Siegel | 0cac176 | 2017-08-09 15:56:45 -0700 | [diff] [blame] | 23 | window.Gerrit = window.Gerrit || {}; |
| 24 | |
Logan Hanks | c11e5a7 | 2016-06-15 12:21:38 -0700 | [diff] [blame] | 25 | /** @polymerBehavior Gerrit.RESTClientBehavior */ |
Becky Siegel | 0cac176 | 2017-08-09 15:56:45 -0700 | [diff] [blame] | 26 | Gerrit.RESTClientBehavior = [{ |
Andrew Bonventre | 8949944 | 2016-02-01 13:42:02 -0800 | [diff] [blame] | 27 | ChangeDiffType: { |
| 28 | ADDED: 'ADDED', |
| 29 | COPIED: 'COPIED', |
| 30 | DELETED: 'DELETED', |
| 31 | MODIFIED: 'MODIFIED', |
| 32 | RENAMED: 'RENAMED', |
| 33 | REWRITE: 'REWRITE', |
| 34 | }, |
| 35 | |
| 36 | ChangeStatus: { |
Andrew Bonventre | 8949944 | 2016-02-01 13:42:02 -0800 | [diff] [blame] | 37 | ABANDONED: 'ABANDONED', |
Viktar Donich | 7bb03b8 | 2016-08-08 12:41:50 -0700 | [diff] [blame] | 38 | MERGED: 'MERGED', |
| 39 | NEW: 'NEW', |
Andrew Bonventre | 8949944 | 2016-02-01 13:42:02 -0800 | [diff] [blame] | 40 | }, |
| 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 Mistry | 6fca1a8 | 2016-10-05 14:19:12 -0400 | [diff] [blame] | 87 | PUSH_CERTIFICATES: 18, |
| 88 | |
| 89 | // Include change's reviewer updates. |
| 90 | REVIEWER_UPDATES: 19, |
| 91 | |
| 92 | // Set the submittable boolean. |
Kasper Nilsson | 8ab1f50 | 2017-05-14 18:10:42 -0700 | [diff] [blame] | 93 | SUBMITTABLE: 20, |
Wyatt Allen | 96b16e7 | 2018-01-18 09:45:44 -0800 | [diff] [blame] | 94 | |
| 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 Paikin | 17b7048 | 2019-07-12 13:46:11 +0200 | [diff] [blame] | 100 | |
| 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 Bonventre | 8949944 | 2016-02-01 13:42:02 -0800 | [diff] [blame] | 106 | }, |
| 107 | |
Kasper Nilsson | 8ab1f50 | 2017-05-14 18:10:42 -0700 | [diff] [blame] | 108 | listChangesOptionsToHex(...args) { |
| 109 | let v = 0; |
| 110 | for (let i = 0; i < args.length; i++) { |
| 111 | v |= 1 << args[i]; |
Andrew Bonventre | 8949944 | 2016-02-01 13:42:02 -0800 | [diff] [blame] | 112 | } |
| 113 | return v.toString(16); |
| 114 | }, |
| 115 | |
Becky Siegel | 8d92d53 | 2017-08-11 16:32:47 -0700 | [diff] [blame] | 116 | /** |
| 117 | * @return {string} |
| 118 | */ |
Logan Hanks | 90b4dc4 | 2018-10-30 09:40:22 -0700 | [diff] [blame] | 119 | changeBaseURL(project, changeNum, patchNum) { |
| 120 | let v = this.getBaseUrl() + '/changes/' + |
| 121 | encodeURIComponent(project) + '~' + changeNum; |
Andrew Bonventre | 8949944 | 2016-02-01 13:42:02 -0800 | [diff] [blame] | 122 | if (patchNum) { |
| 123 | v += '/revisions/' + patchNum; |
| 124 | } |
| 125 | return v; |
| 126 | }, |
David Ostrovsky | e877140 | 2016-02-13 12:23:53 +0100 | [diff] [blame] | 127 | |
Kasper Nilsson | 8ab1f50 | 2017-05-14 18:10:42 -0700 | [diff] [blame] | 128 | changePath(changeNum) { |
Paladox none | 8b0d046 | 2017-03-31 14:37:00 +0000 | [diff] [blame] | 129 | return this.getBaseUrl() + '/c/' + changeNum; |
David Ostrovsky | e877140 | 2016-02-13 12:23:53 +0100 | [diff] [blame] | 130 | }, |
Urs Wolfer | 6ed0958 | 2016-04-07 21:40:39 +0200 | [diff] [blame] | 131 | |
Paladox none | 7dca128 | 2019-07-09 22:45:44 +0000 | [diff] [blame] | 132 | changeIsOpen(change) { |
| 133 | return change && change.status === this.ChangeStatus.NEW; |
Urs Wolfer | 6ed0958 | 2016-04-07 21:40:39 +0200 | [diff] [blame] | 134 | }, |
Viktar Donich | 7bb03b8 | 2016-08-08 12:41:50 -0700 | [diff] [blame] | 135 | |
Becky Siegel | 020e1be | 2017-12-22 12:57:11 -0800 | [diff] [blame] | 136 | /** |
| 137 | * @param {!Object} change |
| 138 | * @param {!Object=} opt_options |
| 139 | * |
| 140 | * @return {!Array} |
| 141 | */ |
| 142 | changeStatuses(change, opt_options) { |
Kasper Nilsson | 66c5d9a | 2017-07-20 12:50:22 -0700 | [diff] [blame] | 143 | const states = []; |
Viktar Donich | 7bb03b8 | 2016-08-08 12:41:50 -0700 | [diff] [blame] | 144 | if (change.status === this.ChangeStatus.MERGED) { |
Kasper Nilsson | 66c5d9a | 2017-07-20 12:50:22 -0700 | [diff] [blame] | 145 | states.push('Merged'); |
| 146 | } else if (change.status === this.ChangeStatus.ABANDONED) { |
| 147 | states.push('Abandoned'); |
Wyatt Allen | 96b16e7 | 2018-01-18 09:45:44 -0800 | [diff] [blame] | 148 | } else if (change.mergeable === false || |
| 149 | (opt_options && opt_options.mergeable === false)) { |
Kasper Nilsson | f73f8cf | 2017-07-21 16:56:19 -0700 | [diff] [blame] | 150 | // 'mergeable' prop may not always exist (@see Issue 6819) |
Kasper Nilsson | 66c5d9a | 2017-07-20 12:50:22 -0700 | [diff] [blame] | 151 | states.push('Merge Conflict'); |
Viktar Donich | 7bb03b8 | 2016-08-08 12:41:50 -0700 | [diff] [blame] | 152 | } |
Kasper Nilsson | 66c5d9a | 2017-07-20 12:50:22 -0700 | [diff] [blame] | 153 | if (change.work_in_progress) { states.push('WIP'); } |
| 154 | if (change.is_private) { states.push('Private'); } |
Becky Siegel | 020e1be | 2017-12-22 12:57:11 -0800 | [diff] [blame] | 155 | |
| 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 Allen | 41816a3 | 2018-04-13 10:56:25 -0700 | [diff] [blame] | 161 | if (change.submittable && opt_options.submitEnabled) { |
Becky Siegel | 020e1be | 2017-12-22 12:57:11 -0800 | [diff] [blame] | 162 | states.push('Ready to submit'); |
| 163 | } else { |
| 164 | // Otherwise it is active. |
| 165 | states.push('Active'); |
| 166 | } |
Becky Siegel | 9b03dd2 | 2017-10-26 14:57:32 -0700 | [diff] [blame] | 167 | return states; |
| 168 | }, |
| 169 | |
Becky Siegel | 020e1be | 2017-12-22 12:57:11 -0800 | [diff] [blame] | 170 | /** |
| 171 | * @param {!Object} change |
| 172 | * @return {String} |
| 173 | */ |
Becky Siegel | 9b03dd2 | 2017-10-26 14:57:32 -0700 | [diff] [blame] | 174 | changeStatusString(change) { |
| 175 | return this.changeStatuses(change).join(', '); |
Viktar Donich | 7bb03b8 | 2016-08-08 12:41:50 -0700 | [diff] [blame] | 176 | }, |
Becky Siegel | 0cac176 | 2017-08-09 15:56:45 -0700 | [diff] [blame] | 177 | }, |
Dmitrii Filippov | b82003c | 2019-11-05 17:02:59 +0100 | [diff] [blame] | 178 | Gerrit.BaseUrlBehavior, |
Paladox none | 8b0d046 | 2017-03-31 14:37:00 +0000 | [diff] [blame] | 179 | ]; |
Andrew Bonventre | 8949944 | 2016-02-01 13:42:02 -0800 | [diff] [blame] | 180 | })(window); |
| 181 | </script> |