Skip to content

Commit 791efb7

Browse files
committed
Labels created
1 parent 14b367d commit 791efb7

File tree

3 files changed

+70
-25
lines changed

3 files changed

+70
-25
lines changed

src/main/java/git/tracehub/pmo/controller/ProjectController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.jcabi.github.Coordinates;
2121
import com.jcabi.github.Repo;
2222
import com.jcabi.github.RtGithub;
23+
import git.tracehub.pmo.platforms.Label;
2324
import git.tracehub.pmo.platforms.RepoPath;
2425
import git.tracehub.pmo.platforms.github.CreateLabel;
2526
import git.tracehub.pmo.platforms.github.InviteCollaborator;
@@ -126,8 +127,9 @@ public Project employ(
126127
).exec();
127128
new CreateLabel(
128129
repo,
129-
new ListOf<>("new"),
130-
new ListOf<>(Color.PINK)
130+
new ListOf<>(
131+
new Label("new", Color.PINK)
132+
)
131133
).exec();
132134
}
133135
return created;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2023-2024 Tracehub.git
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to read
6+
* the Software only. Permissions is hereby NOT GRANTED to use, copy, modify,
7+
* merge, publish, distribute, sublicense, and/or sell copies of the Software.
8+
*
9+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11+
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
12+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
13+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
14+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15+
* SOFTWARE.
16+
*/
17+
18+
package git.tracehub.pmo.platforms;
19+
20+
import java.awt.Color;
21+
import lombok.AllArgsConstructor;
22+
import lombok.Getter;
23+
24+
/**
25+
* Label.
26+
*
27+
* @since 0.0.0
28+
*/
29+
@AllArgsConstructor
30+
@Getter
31+
public final class Label {
32+
33+
/**
34+
* Name.
35+
*/
36+
private String name;
37+
38+
/**
39+
* Color.
40+
*/
41+
private Color color;
42+
43+
}

src/main/java/git/tracehub/pmo/platforms/github/CreateLabel.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@
2121
import com.jcabi.github.Repo;
2222
import git.tracehub.pmo.platforms.Action;
2323
import git.tracehub.pmo.platforms.ColorInHex;
24-
import java.awt.Color;
24+
import git.tracehub.pmo.platforms.Label;
25+
import java.io.IOException;
2526
import java.util.List;
2627
import java.util.stream.StreamSupport;
28+
import lombok.Lombok;
2729
import lombok.RequiredArgsConstructor;
28-
import lombok.SneakyThrows;
2930

3031
/**
3132
* Create label in Github.
@@ -42,32 +43,31 @@ public final class CreateLabel implements Action {
4243
private final Repo repo;
4344

4445
/**
45-
* Names of labels.
46+
* List of labels.
4647
*/
47-
private final List<String> names;
48-
49-
/**
50-
* Colors of labels.
51-
*/
52-
private final List<Color> colors;
48+
private final List<Label> labels;
5349

5450
@Override
55-
@SneakyThrows
5651
public void exec() {
57-
final Labels labels = this.repo.labels();
58-
for (int index = 0; index < this.names.size(); index++) {
59-
final String name = this.names.get(index);
60-
final boolean exists = StreamSupport.stream(
61-
labels.iterate().spliterator(),
62-
false
63-
).anyMatch(label -> name.equals(label.name()));
64-
if (!exists) {
65-
labels.create(
66-
name,
67-
new ColorInHex(this.colors.get(index)).value()
68-
);
52+
final Labels items = this.repo.labels();
53+
this.labels.forEach(
54+
label -> {
55+
final boolean absent = StreamSupport.stream(
56+
items.iterate().spliterator(),
57+
false
58+
).noneMatch(item -> item.name().equals(label.getName()));
59+
if (absent) {
60+
try {
61+
items.create(
62+
label.getName(),
63+
new ColorInHex(label.getColor()).value()
64+
);
65+
} catch (final IOException ex) {
66+
throw Lombok.sneakyThrow(ex);
67+
}
68+
}
6969
}
70-
}
70+
);
7171
}
7272

7373
}

0 commit comments

Comments
 (0)