@@ -43,8 +43,14 @@ public final class GitHubReference extends MessageReceiverAdapter {
43
43
*/
44
44
static final Pattern ISSUE_REFERENCE_PATTERN =
45
45
Pattern .compile ("#(?<%s>\\ d{1,5})" .formatted (ID_GROUP ));
46
- private static final int ISSUE_OPEN = Color .green .getRGB ();
47
- private static final int ISSUE_CLOSE = Color .red .getRGB ();
46
+
47
+ // Representing different GitHub states of an Issue/PR
48
+ private static final Color OPEN_STATE = Color .green ;
49
+ private static final Color CLOSE_STATE = Color .red ;
50
+ private static final Color MERGED_STATE = new Color (141 , 106 , 187 );
51
+ private static final Color NOT_PLANNED_STATE = new Color (72 , 72 , 72 );
52
+ private static final Color DRAFT_STATE = Color .gray ;
53
+
48
54
49
55
/**
50
56
* A constant representing the date and time formatter used for formatting the creation date of
@@ -167,9 +173,7 @@ MessageEmbed generateReply(GHIssue issue) throws UncheckedIOException {
167
173
String dateOfCreation = FORMATTER .format (createdAt );
168
174
169
175
String footer = "%s • %s • %s" .formatted (labels , assignees , dateOfCreation );
170
-
171
- return new EmbedBuilder ()
172
- .setColor (issue .getState () == GHIssueState .OPEN ? ISSUE_OPEN : ISSUE_CLOSE )
176
+ return new EmbedBuilder ().setColor (getIssueStateColor (issue ))
173
177
.setTitle (title , titleUrl )
174
178
.setDescription (description )
175
179
.setAuthor (issue .getUser ().getName (), null , issue .getUser ().getAvatarUrl ())
@@ -181,6 +185,26 @@ MessageEmbed generateReply(GHIssue issue) throws UncheckedIOException {
181
185
}
182
186
}
183
187
188
+ /**
189
+ * Returns the color based on the state of the issue/PR
190
+ */
191
+ private Color getIssueStateColor (GHIssue issue ) throws IOException {
192
+ if (issue instanceof GHPullRequest pr ) {
193
+ if (pr .isMerged ()) {
194
+ return MERGED_STATE ;
195
+ } else if (pr .isDraft ()) {
196
+ return DRAFT_STATE ;
197
+ }
198
+ } else {
199
+ if (issue .getStateReason () == GHIssueStateReason .COMPLETED ) {
200
+ return MERGED_STATE ;
201
+ } else if (issue .getStateReason () == GHIssueStateReason .NOT_PLANNED ) {
202
+ return NOT_PLANNED_STATE ;
203
+ }
204
+ }
205
+ return issue .getState () == GHIssueState .OPEN ? OPEN_STATE : CLOSE_STATE ;
206
+ }
207
+
184
208
/**
185
209
* Either properly gathers the name of a user or throws a UncheckedIOException.
186
210
*/
@@ -199,6 +223,9 @@ Optional<GHIssue> findIssue(int id, String targetIssueTitle) {
199
223
return repositories .stream ().map (repository -> {
200
224
try {
201
225
GHIssue issue = repository .getIssue (id );
226
+ if (issue .isPullRequest ()) {
227
+ issue = repository .getPullRequest (id );
228
+ }
202
229
if (issue .getTitle ().equals (targetIssueTitle )) {
203
230
return Optional .of (issue );
204
231
}
@@ -216,7 +243,11 @@ Optional<GHIssue> findIssue(int id, long defaultRepoId) {
216
243
.filter (repository -> repository .getId () == defaultRepoId )
217
244
.map (repository -> {
218
245
try {
219
- return Optional .of (repository .getIssue (id ));
246
+ GHIssue issue = repository .getIssue (id );
247
+ if (issue .isPullRequest ()) {
248
+ issue = repository .getPullRequest (id );
249
+ }
250
+ return Optional .of (issue );
220
251
} catch (FileNotFoundException ignored ) {
221
252
return Optional .<GHIssue >empty ();
222
253
} catch (IOException ex ) {
0 commit comments