Search in sources :

Example 1 with BasicComponent

use of com.atlassian.jira.rest.client.api.domain.BasicComponent in project opennms by OpenNMS.

the class ListComponentsCommand method doExecute.

@Override
protected void doExecute(JiraRestClient jiraRestClient) throws Exception {
    final String theProjectKey = Strings.isNullOrEmpty(projectKey) ? getConfig().getProjectKey() : projectKey;
    final Iterable<BasicComponent> components = jiraRestClient.getProjectClient().getProject(theProjectKey).get().getComponents();
    if (!components.iterator().hasNext()) {
        System.out.println("No components found for project '" + theProjectKey + "'");
        return;
    }
    System.out.println(String.format(DEFAULT_ROW_FORMAT, "Id", "Name", "Description"));
    for (BasicComponent eachComponent : components) {
        System.out.println(String.format(DEFAULT_ROW_FORMAT, eachComponent.getId(), eachComponent.getName(), eachComponent.getDescription() == null ? "" : removeNewLines(eachComponent.getDescription())));
    }
}
Also used : BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent)

Example 2 with BasicComponent

use of com.atlassian.jira.rest.client.api.domain.BasicComponent in project repository-permissions-updater by jenkins-infra.

the class Hoster method run.

private void run(int issueID) {
    LOGGER.info("Approving hosting request " + issueID);
    JiraRestClient client = null;
    try {
        final HostingRequest hostingRequest = HostingRequestParser.retrieveAndParse(issueID);
        String defaultAssignee = hostingRequest.getJenkinsProjectUsers().get(0);
        String forkFrom = hostingRequest.getRepositoryUrl();
        List<String> users = hostingRequest.getGithubUsers();
        IssueTracker issueTrackerChoice = hostingRequest.getIssueTracker();
        String forkTo = hostingRequest.getNewRepoName();
        if (StringUtils.isBlank(forkFrom) || StringUtils.isBlank(forkTo) || users.isEmpty()) {
            LOGGER.info("Could not retrieve information (or information does not exist) from the Hosting request");
            return;
        }
        // Parse forkFrom in order to determine original repo owner and repo name
        Matcher m = Pattern.compile("(?:https://github\\.com/)?(\\S+)/(\\S+)", CASE_INSENSITIVE).matcher(forkFrom);
        if (m.matches()) {
            if (!forkGitHub(m.group(1), m.group(2), forkTo, users, issueTrackerChoice == IssueTracker.GITHUB)) {
                LOGGER.error("Hosting request failed to fork repository on Github");
                return;
            }
        } else {
            LOGGER.error("ERROR: Cannot parse the source repo: " + forkFrom);
            return;
        }
        // create the JIRA component
        if (issueTrackerChoice == IssueTracker.JIRA && !createComponent(forkTo, defaultAssignee)) {
            LOGGER.error("Hosting request failed to create component " + forkTo + " in JIRA");
            return;
        }
        client = JiraHelper.createJiraClient();
        String componentId = "";
        try {
            if (issueTrackerChoice == IssueTracker.JIRA) {
                BasicComponent component = JiraHelper.getBasicComponent(client, JIRA_PROJECT, forkTo);
                if (component.getId() != null) {
                    componentId = component.getId().toString();
                }
            }
        } catch (IOException | TimeoutException | ExecutionException | InterruptedException ex) {
            LOGGER.error("Could not get component ID for " + forkTo + " component in Jira");
            componentId = "";
        }
        String prUrl = createUploadPermissionPR(issueID, forkTo, users, hostingRequest.getJenkinsProjectUsers(), issueTrackerChoice == IssueTracker.GITHUB, componentId);
        if (StringUtils.isBlank(prUrl)) {
            LOGGER.error("Could not create upload permission pull request");
        }
        String prDescription = "";
        String repoPermissionsActionText = "Create PR for upload permissions";
        if (!StringUtils.isBlank(prUrl)) {
            prDescription = "\n\nA [pull request](" + prUrl + ") has been created against the repository permissions updater to " + "setup release permissions. Additional users can be added by modifying the created file.";
            repoPermissionsActionText = "Add additional users for upload permissions, if needed";
        }
        String issueTrackerText;
        if (issueTrackerChoice == IssueTracker.JIRA) {
            issueTrackerText = "\n\nA Jira component named " + forkTo + " has also been created with " + defaultAssignee + " as the default assignee for issues.";
        } else {
            issueTrackerText = "\n\nGitHub issues has been selected for issue tracking and was enabled for the forked repo.";
        }
        // update the issue with information on next steps
        String msg = "Hosting request complete, the code has been forked into the jenkinsci project on GitHub as " + "https://github.com/jenkinsci/" + forkTo + issueTrackerText + prDescription + "\n\nPlease remove your original repository (if there are no other forks) so that the jenkinsci organization repository " + "is the definitive source for the code. If there are other forks, please contact GitHub support to make the jenkinsci repo the root of the fork network (mention that Jenkins approval was given in support request 569994). " + "Also, please make sure you properly follow the [documentation on documenting your plugin](https://jenkins.io/doc/developer/publishing/documentation/) " + "so that your plugin is correctly documented. \n\n" + "You will also need to do the following in order to push changes and release your plugin: \n\n" + "* [Accept the invitation to the Jenkins CI Org on Github](https://github.com/jenkinsci)\n" + "* [" + repoPermissionsActionText + "](https://github.com/jenkins-infra/repository-permissions-updater/#requesting-permissions)\n" + "* [Releasing your plugin](https://jenkins.io/doc/developer/publishing/releasing/)\n" + "\n\nIn order for your plugin to be built by the [Jenkins CI Infrastructure](https://ci.jenkins.io) and check pull requests," + " please add a [Jenkinsfile](https://jenkins.io/doc/book/pipeline/jenkinsfile/) to the root of your repository with the following content:\n" + "`buildPlugin()`" + "\n\nWelcome aboard!";
        // add comment
        GitHub github = GitHub.connect();
        GHIssue issue = github.getRepository(HOSTING_REPO_SLUG).getIssue(issueID);
        issue.comment(msg);
        issue.close();
        LOGGER.info("Hosting setup complete");
    } catch (IOException e) {
        LOGGER.error("Failed setting up hosting for " + issueID + ". ", e);
    } finally {
        if (!JiraHelper.close(client)) {
            LOGGER.warn("Failed to close JIRA client, possible leaked file descriptors");
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) IssueTracker(io.jenkins.infra.repository_permissions_updater.hosting.HostingRequest.IssueTracker) GitHub(org.kohsuke.github.GitHub) GHIssue(org.kohsuke.github.GHIssue) IOException(java.io.IOException) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with BasicComponent

use of com.atlassian.jira.rest.client.api.domain.BasicComponent in project seleniumRobot by bhecquet.

the class JiraConnector method createIssue.

/**
 * Create issue
 */
public void createIssue(IssueBean issueBean) {
    if (!(issueBean instanceof JiraBean)) {
        throw new ClassCastException("JiraConnector needs JiraBean instances");
    }
    JiraBean jiraBean = (JiraBean) issueBean;
    IssueType issueType = issueTypes.get(jiraBean.getIssueType());
    if (issueType == null) {
        throw new ConfigurationException(String.format("Issue type %s cannot be found among valid issue types %s", jiraBean.getIssueType(), issueTypes.keySet()));
    }
    Map<String, CimFieldInfo> fieldInfos = getCustomFieldInfos(project, issueType);
    IssueRestClient issueClient = restClient.getIssueClient();
    IssueInputBuilder issueBuilder = new IssueInputBuilder(project, issueType, jiraBean.getSummary()).setDescription(jiraBean.getDescription());
    if (isDueDateRequired(fieldInfos)) {
        issueBuilder.setDueDate(jiraBean.getJodaDateTime());
    }
    if (jiraBean.getAssignee() != null && !jiraBean.getAssignee().isEmpty()) {
        User user = getUser(jiraBean.getAssignee());
        if (user == null) {
            throw new ConfigurationException(String.format("Assignee %s cannot be found among jira users", jiraBean.getAssignee()));
        }
        issueBuilder.setAssignee(user);
    }
    if (jiraBean.getPriority() != null && !jiraBean.getPriority().isEmpty()) {
        Priority priority = priorities.get(jiraBean.getPriority());
        if (priority == null) {
            throw new ConfigurationException(String.format("Priority %s cannot be found on this jira project, valid priorities are %s", jiraBean.getPriority(), priorities.keySet()));
        }
        issueBuilder.setPriority(priority);
    }
    if (jiraBean.getReporter() != null && !jiraBean.getReporter().isEmpty()) {
        issueBuilder.setReporterName(jiraBean.getReporter());
    }
    // set fields
    setCustomFields(jiraBean, fieldInfos, issueBuilder);
    // set components
    issueBuilder.setComponents(jiraBean.getComponents().stream().filter(component -> components.get(component) != null).map(component -> components.get(component)).collect(Collectors.toList()).toArray(new BasicComponent[] {}));
    // add issue
    IssueInput newIssue = issueBuilder.build();
    BasicIssue basicIssue = issueClient.createIssue(newIssue).claim();
    Issue issue = issueClient.getIssue(basicIssue.getKey()).claim();
    addAttachments(jiraBean, issueClient, issue);
    jiraBean.setId(issue.getKey());
    jiraBean.setAccessUrl(browseUrl + issue.getKey());
}
Also used : Arrays(java.util.Arrays) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) Priority(com.atlassian.jira.rest.client.api.domain.Priority) Issue(com.atlassian.jira.rest.client.api.domain.Issue) URISyntaxException(java.net.URISyntaxException) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) HashMap(java.util.HashMap) Snapshot(com.seleniumtests.reporter.logger.Snapshot) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) SeleniumTestsContextManager(com.seleniumtests.core.SeleniumTestsContextManager) Logger(org.apache.log4j.Logger) BugTracker(com.seleniumtests.connectors.bugtracker.BugTracker) WaitHelper(com.seleniumtests.util.helper.WaitHelper) ImmutableList(com.google.common.collect.ImmutableList) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Map(java.util.Map) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) Project(com.atlassian.jira.rest.client.api.domain.Project) URI(java.net.URI) ScenarioException(com.seleniumtests.customexception.ScenarioException) RestClientException(com.atlassian.jira.rest.client.api.RestClientException) Transition(com.atlassian.jira.rest.client.api.domain.Transition) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) CustomFieldOption(com.atlassian.jira.rest.client.api.domain.CustomFieldOption) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder) TransitionInput(com.atlassian.jira.rest.client.api.domain.input.TransitionInput) Field(com.atlassian.jira.rest.client.api.domain.Field) Collectors(java.util.stream.Collectors) ScreenShot(com.seleniumtests.driver.screenshots.ScreenShot) File(java.io.File) SearchRestClient(com.atlassian.jira.rest.client.api.SearchRestClient) List(java.util.List) User(com.atlassian.jira.rest.client.api.domain.User) Version(com.atlassian.jira.rest.client.api.domain.Version) BasicProject(com.atlassian.jira.rest.client.api.domain.BasicProject) TestStep(com.seleniumtests.reporter.logger.TestStep) Entry(java.util.Map.Entry) Comment(com.atlassian.jira.rest.client.api.domain.Comment) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) AsynchronousJiraRestClientFactory(com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory) IssueBean(com.seleniumtests.connectors.bugtracker.IssueBean) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) User(com.atlassian.jira.rest.client.api.domain.User) Issue(com.atlassian.jira.rest.client.api.domain.Issue) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) CimFieldInfo(com.atlassian.jira.rest.client.api.domain.CimFieldInfo) Priority(com.atlassian.jira.rest.client.api.domain.Priority) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) IssueRestClient(com.atlassian.jira.rest.client.api.IssueRestClient) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) BasicComponent(com.atlassian.jira.rest.client.api.domain.BasicComponent) IssueInputBuilder(com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder)

Aggregations

BasicComponent (com.atlassian.jira.rest.client.api.domain.BasicComponent)3 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)2 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)1 RestClientException (com.atlassian.jira.rest.client.api.RestClientException)1 SearchRestClient (com.atlassian.jira.rest.client.api.SearchRestClient)1 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)1 BasicPriority (com.atlassian.jira.rest.client.api.domain.BasicPriority)1 BasicProject (com.atlassian.jira.rest.client.api.domain.BasicProject)1 CimFieldInfo (com.atlassian.jira.rest.client.api.domain.CimFieldInfo)1 Comment (com.atlassian.jira.rest.client.api.domain.Comment)1 CustomFieldOption (com.atlassian.jira.rest.client.api.domain.CustomFieldOption)1 Field (com.atlassian.jira.rest.client.api.domain.Field)1 Issue (com.atlassian.jira.rest.client.api.domain.Issue)1 IssueType (com.atlassian.jira.rest.client.api.domain.IssueType)1 Priority (com.atlassian.jira.rest.client.api.domain.Priority)1 Project (com.atlassian.jira.rest.client.api.domain.Project)1 Transition (com.atlassian.jira.rest.client.api.domain.Transition)1 User (com.atlassian.jira.rest.client.api.domain.User)1 Version (com.atlassian.jira.rest.client.api.domain.Version)1 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)1