// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/GitHubPRLabel.java
// public class GitHubPRLabel implements Describable<GitHubPRLabel> {
//     private Set<String> labels;
// 
//     @DataBoundConstructor
//     public GitHubPRLabel(String labels) {
//         this(new HashSet<>(Arrays.asList(labels.split("\n"))));
//     }
// 
//     public GitHubPRLabel(Set<String> labels) {
//         this.labels = labels;
//     }
// 
//     // for UI binding
//     public String getLabels() {
//         return Joiner.on("\n").skipNulls().join(labels);
//     }
// 
//     @NonNull
//     public Set<String> getLabelsSet() {
//         return nonNull(labels) ? labels : Collections.<String>emptySet();
//     }
// 
//     public DescriptorImpl getDescriptor() {
//         return (DescriptorImpl) Jenkins.getInstance().getDescriptor(GitHubPRLabel.class);
//     }
// 
//     @Symbol("labels")
//     @Extension
//     public static class DescriptorImpl extends Descriptor<GitHubPRLabel> {
//         @NonNull
//         @Override
//         public String getDisplayName() {
//             return "Labels";
//         }
//     }
// }
// 
// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/publishers/GitHubPRAbstractPublisher.java
// public abstract class GitHubPRAbstractPublisher extends Recorder implements SimpleBuildStep {
// 
//     @CheckForNull
//     private StatusVerifier statusVerifier;
// 
//     @CheckForNull
//     private PublisherErrorHandler errorHandler;
// 
//     public GitHubPRAbstractPublisher(StatusVerifier statusVerifier, PublisherErrorHandler errorHandler) {
//         this.statusVerifier = statusVerifier;
//         this.errorHandler = errorHandler;
//     }
// 
//     public StatusVerifier getStatusVerifier() {
//         return statusVerifier;
//     }
// 
//     public PublisherErrorHandler getErrorHandler() {
//         return errorHandler;
//     }
// 
//     protected void handlePublisherError(Run<?, ?> run) {
//         if (errorHandler != null) {
//             errorHandler.markBuildAfterError(run);
//         }
//     }
// 
//     public final BuildStepMonitor getRequiredMonitorService() {
//         return BuildStepMonitor.NONE;
//     }
// 
//     public final GitHubPRTrigger.DescriptorImpl getTriggerDescriptor() {
//         return (GitHubPRTrigger.DescriptorImpl) Jenkins.getInstance().getDescriptor(GitHubPRTrigger.class);
//     }
// 
//     public abstract static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
//         @Override
//         public final boolean isApplicable(final Class<? extends AbstractProject> jobType) {
//             return true;
//         }
// 
//         @Override
//         public abstract String getDisplayName();
//     }
// }
// 
// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/utils/PublisherErrorHandler.java
// public class PublisherErrorHandler extends AbstractDescribableImpl<PublisherErrorHandler> {
// 
//     private Result buildStatus;
// 
//     @DataBoundConstructor
//     public PublisherErrorHandler(Result buildStatus) {
//         this.buildStatus = buildStatus;
//     }
// 
//     public Result getBuildStatus() {
//         return buildStatus;
//     }
// 
//     public Result markBuildAfterError(Run<?, ?> run) {
//         run.setResult(buildStatus);
//         return buildStatus;
//     }
// 
//     @Symbol("statusOnPublisherError")
//     @Extension
//     public static class DescriptorImpl extends Descriptor<PublisherErrorHandler> {
//         @NonNull
//         @Override
//         public String getDisplayName() {
//             return "Set build status if publisher failed";
//         }
// 
//         public ListBoxModel doFillBuildStatusItems() {
//             ListBoxModel items = new ListBoxModel();
//             items.add(Result.UNSTABLE.toString());
//             items.add(Result.FAILURE.toString());
//             return items;
//         }
//     }
// }
// 
// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/utils/JobHelper.java
// public static GHIssue getGhIssue(final Run<?, ?> run) throws IOException {
//     return getGhRepositoryFromPRTrigger(run).getIssue(getPRNumberFromPRCause(run));
// }
// 
// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/utils/JobHelper.java
// public static int getPRNumberFromPRCause(final Run<?, ?> run) throws AbortException {
//     GitHubPRCause cause = ghPRCauseFromRun(run);
//     if (isNull(cause)) {
//         throw new AbortException("Can't get cause from run/build");
//     }
//     return cause.getNumber();
// }


import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import jenkins.model.Jenkins;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.github.pullrequest.GitHubPRLabel;
import org.jenkinsci.plugins.github.pullrequest.publishers.GitHubPRAbstractPublisher;
import org.jenkinsci.plugins.github.pullrequest.utils.PublisherErrorHandler;
import org.jenkinsci.plugins.github.pullrequest.utils.StatusVerifier;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHLabel;
import org.kohsuke.stapler.DataBoundConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.util.HashSet;
import java.util.stream.Collectors;
import static org.jenkinsci.plugins.github.pullrequest.utils.JobHelper.getGhIssue;
import static org.jenkinsci.plugins.github.pullrequest.utils.JobHelper.getPRNumberFromPRCause;
package org.jenkinsci.plugins.github.pullrequest.publishers.impl;




/**
 * Implements addition of labels (one or many) to GitHub.
 *
 * @author Alina Karpovich
 * @author Kanstantsin Shautsou
 */
public class GitHubPRLabelAddPublisher extends GitHubPRAbstractPublisher {
    private static final Logger LOGGER = LoggerFactory.getLogger(GitHubPRLabelAddPublisher.class);

    private GitHubPRLabel labelProperty;

    @DataBoundConstructor
    public GitHubPRLabelAddPublisher(GitHubPRLabel labelProperty,
                                     StatusVerifier statusVerifier,
// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/GitHubPRLabel.java
// public class GitHubPRLabel implements Describable<GitHubPRLabel> {
//     private Set<String> labels;
// 
//     @DataBoundConstructor
//     public GitHubPRLabel(String labels) {
//         this(new HashSet<>(Arrays.asList(labels.split("\n"))));
//     }
// 
//     public GitHubPRLabel(Set<String> labels) {
//         this.labels = labels;
//     }
// 
//     // for UI binding
//     public String getLabels() {
//         return Joiner.on("\n").skipNulls().join(labels);
//     }
// 
//     @NonNull
//     public Set<String> getLabelsSet() {
//         return nonNull(labels) ? labels : Collections.<String>emptySet();
//     }
// 
//     public DescriptorImpl getDescriptor() {
//         return (DescriptorImpl) Jenkins.getInstance().getDescriptor(GitHubPRLabel.class);
//     }
// 
//     @Symbol("labels")
//     @Extension
//     public static class DescriptorImpl extends Descriptor<GitHubPRLabel> {
//         @NonNull
//         @Override
//         public String getDisplayName() {
//             return "Labels";
//         }
//     }
// }
// 
// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/publishers/GitHubPRAbstractPublisher.java
// public abstract class GitHubPRAbstractPublisher extends Recorder implements SimpleBuildStep {
// 
//     @CheckForNull
//     private StatusVerifier statusVerifier;
// 
//     @CheckForNull
//     private PublisherErrorHandler errorHandler;
// 
//     public GitHubPRAbstractPublisher(StatusVerifier statusVerifier, PublisherErrorHandler errorHandler) {
//         this.statusVerifier = statusVerifier;
//         this.errorHandler = errorHandler;
//     }
// 
//     public StatusVerifier getStatusVerifier() {
//         return statusVerifier;
//     }
// 
//     public PublisherErrorHandler getErrorHandler() {
//         return errorHandler;
//     }
// 
//     protected void handlePublisherError(Run<?, ?> run) {
//         if (errorHandler != null) {
//             errorHandler.markBuildAfterError(run);
//         }
//     }
// 
//     public final BuildStepMonitor getRequiredMonitorService() {
//         return BuildStepMonitor.NONE;
//     }
// 
//     public final GitHubPRTrigger.DescriptorImpl getTriggerDescriptor() {
//         return (GitHubPRTrigger.DescriptorImpl) Jenkins.getInstance().getDescriptor(GitHubPRTrigger.class);
//     }
// 
//     public abstract static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
//         @Override
//         public final boolean isApplicable(final Class<? extends AbstractProject> jobType) {
//             return true;
//         }
// 
//         @Override
//         public abstract String getDisplayName();
//     }
// }
// 
// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/utils/PublisherErrorHandler.java
// public class PublisherErrorHandler extends AbstractDescribableImpl<PublisherErrorHandler> {
// 
//     private Result buildStatus;
// 
//     @DataBoundConstructor
//     public PublisherErrorHandler(Result buildStatus) {
//         this.buildStatus = buildStatus;
//     }
// 
//     public Result getBuildStatus() {
//         return buildStatus;
//     }
// 
//     public Result markBuildAfterError(Run<?, ?> run) {
//         run.setResult(buildStatus);
//         return buildStatus;
//     }
// 
//     @Symbol("statusOnPublisherError")
//     @Extension
//     public static class DescriptorImpl extends Descriptor<PublisherErrorHandler> {
//         @NonNull
//         @Override
//         public String getDisplayName() {
//             return "Set build status if publisher failed";
//         }
// 
//         public ListBoxModel doFillBuildStatusItems() {
//             ListBoxModel items = new ListBoxModel();
//             items.add(Result.UNSTABLE.toString());
//             items.add(Result.FAILURE.toString());
//             return items;
//         }
//     }
// }
// 
// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/utils/JobHelper.java
// public static GHIssue getGhIssue(final Run<?, ?> run) throws IOException {
//     return getGhRepositoryFromPRTrigger(run).getIssue(getPRNumberFromPRCause(run));
// }
// 
// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/utils/JobHelper.java
// public static int getPRNumberFromPRCause(final Run<?, ?> run) throws AbortException {
//     GitHubPRCause cause = ghPRCauseFromRun(run);
//     if (isNull(cause)) {
//         throw new AbortException("Can't get cause from run/build");
//     }
//     return cause.getNumber();
// }


// Path: github-pullrequest-plugin/src/main/java/org/jenkinsci/plugins/github/pullrequest/publishers/impl/GitHubPRLabelAddPublisher.java
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import jenkins.model.Jenkins;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.github.pullrequest.GitHubPRLabel;
import org.jenkinsci.plugins.github.pullrequest.publishers.GitHubPRAbstractPublisher;
import org.jenkinsci.plugins.github.pullrequest.utils.PublisherErrorHandler;
import org.jenkinsci.plugins.github.pullrequest.utils.StatusVerifier;
import org.kohsuke.github.GHIssue;
import org.kohsuke.github.GHLabel;
import org.kohsuke.stapler.DataBoundConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.util.HashSet;
import java.util.stream.Collectors;
import static org.jenkinsci.plugins.github.pullrequest.utils.JobHelper.getGhIssue;
import static org.jenkinsci.plugins.github.pullrequest.utils.JobHelper.getPRNumberFromPRCause;

package org.jenkinsci.plugins.github.pullrequest.publishers.impl;




/**
 * Implements addition of labels (one or many) to GitHub.
 *
 * @author Alina Karpovich
 * @author Kanstantsin Shautsou
 */
public class GitHubPRLabelAddPublisher extends GitHubPRAbstractPublisher {
    private static final Logger LOGGER = LoggerFactory.getLogger(GitHubPRLabelAddPublisher.class);

    private GitHubPRLabel labelProperty;

    @DataBoundConstructor
    public GitHubPRLabelAddPublisher(GitHubPRLabel labelProperty,
                                     StatusVerifier statusVerifier,
                                     PublisherErrorHandler errorHandler) {