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())));
}
}
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");
}
}
}
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());
}
Aggregations