aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/Pullrequest.java
blob: b69805ebce59ec1d747c8c7302638778031d6143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
package bitbucketpullrequestbuilder.bitbucketpullrequestbuilder.bitbucket;

import java.util.List;
import java.util.Comparator;
import java.util.Map;

import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;

/**
 * POJOs representing the pull-requests extracted from the
 * JSON response of the Bitbucket API V2.
 *
 * @see "https://confluence.atlassian.com/bitbucket/pullrequests-resource-423626332.html#pullrequestsResource-GETaspecificpullrequest"
 */

@JsonIgnoreProperties(ignoreUnknown = true)
public class Pullrequest {

    private String     description;
    private Boolean    closeSourceBranch;
    private String     title;
    private Revision   destination;
    private String     reason;
    private String     closedBy;
    private Revision   source;
    private String     state;
    private String     createdOn;
    private String     updatedOn;
    private String     mergeCommit;
    private String     id;
    private Author     author;

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Response<T> {
        private int pageLength;
        private List<T> values;
        private int page;
        private int size;
        private String next;

        @JsonProperty("pagelen")
        public int getPageLength() {
            return pageLength;
        }
        @JsonProperty("pagelen")
        public void setPageLength(int pageLength) {
            this.pageLength = pageLength;
        }
        public List<T> getValues() {
            return values;
        }
        public void setValues(List<T> values) {
            this.values = values;
        }
        public int getPage() {
            return page;
        }
        public void setPage(int page) {
            this.page = page;
        }
        public int getSize() {
            return size;
        }
        public void setSize(int size) {
            this.size = size;
        }
        public String getNext() {
            return next;
        }
        public void setNext(String next) {
            this.next = next;
        }
    }


    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Revision {
        private Repository repository;
        private Branch branch;
        private Commit commit;

        public Repository getRepository() {
            return repository;
        }
        public void setRepository(Repository repository) {
            this.repository = repository;
        }
        public Branch getBranch() {
            return branch;
        }
        public void setBranch(Branch branch) {
            this.branch = branch;
        }
        public Commit getCommit() {
            return commit;
        }
        public void setCommit(Commit commit) {
            this.commit = commit;
        }
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Repository {
        private String fullName;
        private String name;
        private String ownerName;
        private String repositoryName;

        @JsonProperty("full_name")
        public String getFullName() {
            return fullName;
        }
        @JsonProperty("full_name")
        public void setFullName(String fullName) {
            // Also extract owner- and reponame
            if (fullName != null) {
                this.ownerName = fullName.split("/")[0];
                this.repositoryName = fullName.split("/")[1];
            }
            this.fullName = fullName;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getOwnerName() {
            return ownerName;
        }
        public String getRepositoryName() {
            return repositoryName;
        }
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Branch {
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Commit {
        private String hash;

        public String getHash() {
            return hash;
        }

        public void setHash(String hash) {
            this.hash = hash;
        }
    }

    // Was: Approval
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Participant {
        private String role;
        private Boolean approved;

        public String getRole() {
            return role;
        }
        public void setRole(String role) {
            this.role = role;
        }
        public Boolean getApproved() {
            return approved;
        }
        public void setApproved(Boolean approved) {
            this.approved = approved;
        }
    }

    // https://confluence.atlassian.com/bitbucket/pullrequests-resource-1-0-296095210.html#pullrequestsResource1.0-POSTanewcomment
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Comment implements Comparable<Comment> {
        private Integer id;
        private String  filename;
        private String  content;

        @Override
        public int compareTo(Comment target) {
            if (target == null){
                return -1;
            } else if (this.getId() > target.getId()) {
                return 1;
            } else if (this.getId().equals(target.getId())) {
                return 0;
            } else {
                return -1;
            }
        }

        @Override
        public boolean equals(final Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            final Comment comment = (Comment) o;

            return getId() != null ? getId().equals(comment.getId()) : comment.getId() == null;
        }

        @Override
        public int hashCode() {
            return getId() != null ? getId().hashCode() : 0;
        }

        public Integer getId() {
            return id;
        }

        public void setId(Integer id) {
            this.id = id;
        }

        public String getFilename() {
            return filename;
        }

        public void setFilename(String filename) {
            this.filename = filename;
        }

        public String getContent() {
            return content;
        }

        public void setContent(Object content) {
            if (content instanceof String) {
                this.content = (String)content;
            } else if (content instanceof Map){
                this.content = (String)((Map)content).get("raw");
            }
            return;
        }

    }
    
    @JsonIgnoreProperties(ignoreUnknown = true)
    public static class Author {
      private String username;
      private String display_name;
      public static final String COMBINED_NAME = "%s <@%s>";
      
      public String getUsername() {
          return username;
      }
      public void setUsername(String username) {
          this.username = username;
      }
      
      @JsonProperty("display_name")
      public String getDisplayName() {
          return display_name;
      }
      
      @JsonProperty("display_name")
      public void setDisplayName(String display_name) {
          this.display_name = display_name;
      }
      public String getCombinedUsername() {
        return String.format(COMBINED_NAME, this.getDisplayName(), this.getUsername());
      }
    }

    //-------------------- only getters and setters follow -----------------

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @JsonProperty("close_source_branch")
    public Boolean getCloseSourceBranch() {
        return closeSourceBranch;
    }

    @JsonProperty("close_source_branch")
    public void setCloseSourceBranch(Boolean closeSourceBranch) {
        this.closeSourceBranch = closeSourceBranch;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Revision getDestination() {
        return destination;
    }

    public void setDestination(Revision destination) {
        this.destination = destination;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }

    @JsonProperty("closed_by")
    public String getClosedBy() {
        return closedBy;
    }

    @JsonProperty("closed_by")
    public void setClosedBy(String closedBy) {
        this.closedBy = closedBy;
    }

    public Revision getSource() {
        return source;
    }

    public void setSource(Revision source) {
        this.source = source;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    @JsonProperty("created_on")
    public String getCreatedOn() {
        return createdOn;
    }

    @JsonProperty("created_on")
    public void setCreatedOn(String createdOn) {
        this.createdOn = createdOn;
    }

    @JsonProperty("updated_on")
    public String getUpdatedOn() {
        return updatedOn;
    }

    @JsonProperty("updated_on")
    public void setUpdatedOn(String updatedOn) {
        this.updatedOn = updatedOn;
    }

    @JsonProperty("merge_commit")
    public String getMergeCommit() {
        return mergeCommit;
    }

    @JsonProperty("merge_commit")
    public void setMergeCommit(String mergeCommit) {
        this.mergeCommit = mergeCommit;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
    
    public Author getAuthor() {
      return this.author;
    }
    
    public void setAutohor(Author author) {
      this.author = author;
    }

}