|
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | 4 | class GitLabApiClient { |
| 5 | + /** |
| 6 | + * The GitLab API client used by the extension. No tokens or authentication needed as every requests are |
| 7 | + * performed from inside the context of the page (GitLab allows API calls if they comes from the site). |
| 8 | + */ |
5 | 9 | constructor(baseUrl) { |
6 | 10 | this.baseUrl = baseUrl; |
7 | 11 | } |
8 | 12 |
|
9 | 13 | /** |
10 | | - * Create an `URL` object representing the full URL to the given GitLab API endpoint. |
| 14 | + * Creates an `URL` object representing the full URL to the given GitLab API endpoint. |
11 | 15 | */ |
12 | 16 | createEndpointUrl(endpoint, queryStringParameters = null) { |
13 | 17 | let url = new URL(this.baseUrl + endpoint); |
|
21 | 25 | return url; |
22 | 26 | } |
23 | 27 |
|
24 | | - sendRequest(method, endpoint, callback, queryStringParameters = null) { |
| 28 | + /** |
| 29 | + * Sends an HTTP request to the GitLab API. |
| 30 | + */ |
| 31 | + sendRequest(callback, method, endpoint, queryStringParameters = null) { |
25 | 32 | let xhr = new XMLHttpRequest(); |
26 | 33 |
|
27 | 34 | xhr.responseType = 'json'; |
|
37 | 44 | } |
38 | 45 |
|
39 | 46 | /** |
40 | | - * Fetch details about the given Merge Requests IDs. |
| 47 | + * Fetch details about the given Merge Requests IDs in the given project ID. |
41 | 48 | */ |
42 | | - getMergeRequests(projectId, mergeRequestIds, callback) { |
| 49 | + getProjectMergeRequests(callback, projectId, mergeRequestIds) { |
43 | 50 | let queryStringParameters = mergeRequestIds.map(function(mergeRequestId) { |
44 | 51 | return ['iids[]', mergeRequestId]; |
45 | 52 | }); |
46 | 53 |
|
47 | 54 | this.sendRequest( |
| 55 | + callback, |
48 | 56 | 'GET', |
49 | 57 | 'projects/' + projectId + '/merge_requests', |
50 | | - callback, |
51 | 58 | queryStringParameters |
52 | 59 | ); |
53 | 60 | } |
|
139 | 146 | fetchMergeRequestsDetails(mergeRequestIds) { |
140 | 147 | let self = this; |
141 | 148 |
|
142 | | - this.apiClient.getMergeRequests( |
143 | | - this.currentProjectId, |
144 | | - mergeRequestIds, |
| 149 | + this.apiClient.getProjectMergeRequests( |
145 | 150 | function() { |
146 | 151 | if (this.status == 200) { |
147 | 152 | self.updateMergeRequestsNodes(this.response); |
148 | 153 | } else { |
149 | 154 | console.error('Got error from GitLab:', this.status, this.response); |
150 | 155 | } |
151 | | - } |
| 156 | + }, |
| 157 | + this.currentProjectId, |
| 158 | + mergeRequestIds |
152 | 159 | ); |
153 | 160 | } |
154 | 161 |
|
|
0 commit comments