22
33import java .io .IOException ;
44import java .time .LocalDateTime ;
5+ import java .util .ArrayList ;
6+ import java .util .Arrays ;
7+ import java .util .Collections ;
8+ import java .util .List ;
59import java .util .logging .Level ;
610import java .util .logging .Logger ;
711
812import org .kohsuke .stapler .DataBoundConstructor ;
913import org .kohsuke .stapler .DataBoundSetter ;
1014
1115import com .gitee .jenkins .gitee .api .GiteeClient ;
16+ import com .gitee .jenkins .gitee .api .model .Label ;
1217import com .gitee .jenkins .gitee .api .model .PullRequest ;
1318import com .gitee .jenkins .gitee .api .model .builder .generated .PullRequestBuilder ;
1419import com .gitee .jenkins .util .LoggerUtil ;
2025import hudson .matrix .MatrixAggregator ;
2126import hudson .matrix .MatrixBuild ;
2227import hudson .model .AbstractBuild ;
28+ import hudson .model .AbstractDescribableImpl ;
2329import hudson .model .AbstractProject ;
2430import hudson .model .BuildListener ;
31+ import hudson .model .Descriptor ;
2532import hudson .model .Result ;
2633import hudson .tasks .BuildStepDescriptor ;
2734import hudson .tasks .BuildStepMonitor ;
@@ -38,6 +45,7 @@ public class GiteeCreatePullRequestPublisher extends Notifier implements MatrixA
3845 private String base ;
3946 private String head ;
4047 private String body ;
48+ private List <LabelNameEntry > labelNames = Collections .<LabelNameEntry >emptyList ();
4149 private boolean addDatetime ;
4250
4351 @ DataBoundConstructor
@@ -76,6 +84,10 @@ public String getBody() {
7684 return body ;
7785 }
7886
87+ public List <LabelNameEntry > getLabelNames () {
88+ return labelNames ;
89+ }
90+
7991 @ DataBoundSetter
8092 public void setRepo (String repo ) {
8193 this .repo = repo ;
@@ -111,9 +123,21 @@ public void setBody(String body) {
111123 this .body = body ;
112124 }
113125
126+ @ DataBoundSetter
127+ public void setLabelNames (List <LabelNameEntry > labelNames ) {
128+ this .labelNames = labelNames ;
129+ }
130+
114131 @ Override
115132 public boolean perform (AbstractBuild <?, ?> build , Launcher launcher , BuildListener listener )
116133 throws InterruptedException , IOException {
134+
135+ ArrayList <String > labels = new ArrayList <String >();
136+ for (LabelNameEntry entry : labelNames ) {
137+ if (!labels .contains (entry .toString ())) {
138+ labels .add (entry .toString ());
139+ }
140+ }
117141
118142 GiteeClient client = getClient (build );
119143 if (client == null ) {
@@ -138,6 +162,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
138162 .withSourceBranch (head )
139163 .withTargetBranch (base )
140164 .withDescription (body )
165+ .withLabels (labels )
141166 .build ();
142167
143168 if (!client .getPullRequest (pr ).isEmpty ()) {
@@ -203,5 +228,31 @@ public boolean isApplicable(Class<? extends AbstractProject> aClass) {
203228 public String getDisplayName () {
204229 return Messages .GiteeCreatePullRequestPublisher_DisplayName ();
205230 }
231+
232+ }
233+
234+ public static final class LabelNameEntry extends AbstractDescribableImpl <LabelNameEntry > {
235+ private final String text ;
236+
237+ @ DataBoundConstructor public LabelNameEntry (String text ) {
238+ this .text = text ;
239+ }
240+
241+ public String getText () {
242+ return text ;
243+ }
244+
245+ @ Override
246+ public String toString () {
247+ return text ;
248+ }
249+
250+ @ Extension
251+ public static class DescriptorImpl extends Descriptor <LabelNameEntry > {
252+ @ Override
253+ public String getDisplayName () {
254+ return "Label" ;
255+ }
256+ }
206257 }
207258}
0 commit comments