Search in sources :

Example 6 with Priority

use of com.atlassian.jira.rest.client.api.domain.Priority in project jira-plugin by jenkinsci.

the class JiraCreateIssueNotifier method createJiraIssue.

/**
 * It creates a issue in the given project, with the given description, assignee,components and summary.
 * The created issue ID is saved to the file at "filename".
 *
 * @param build
 * @param filename
 * @return issue id
 * @throws IOException
 * @throws InterruptedException
 */
private Issue createJiraIssue(AbstractBuild<?, ?> build, String filename) throws IOException, InterruptedException {
    EnvVars vars = build.getEnvironment(TaskListener.NULL);
    JiraSession session = getJiraSession(build);
    String buildName = getBuildName(vars);
    String summary = String.format("Build %s failed", buildName);
    String description = String.format("%s\n\nThe build %s has failed.\nFirst failed run: %s", (this.testDescription.equals("")) ? "No description is provided" : vars.expand(this.testDescription), buildName, getBuildDetailsString(vars));
    Iterable<String> components = Arrays.stream(component.split(",")).filter(s -> !StringUtils.isEmpty(s)).map(s -> StringUtils.trim(s)).collect(Collectors.toList());
    Long type = typeId;
    if (type == null || type == 0) {
        // zero is default / invalid selection
        LOG.info("Returning default issue type id " + BUG_ISSUE_TYPE_ID);
        type = BUG_ISSUE_TYPE_ID;
    }
    Long priority = priorityId;
    if (priority != null && priority == 0) {
        // remove invalid priority selection
        priority = null;
    }
    Issue issue = session.createIssue(projectKey, description, assignee, components, summary, type, priority);
    writeInFile(filename, issue);
    return issue;
}
Also used : BUG_ISSUE_TYPE_ID(hudson.plugins.jira.JiraRestService.BUG_ISSUE_TYPE_ID) Priority(com.atlassian.jira.rest.client.api.domain.Priority) StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) Issue(com.atlassian.jira.rest.client.api.domain.Issue) DataBoundConstructor(org.kohsuke.stapler.DataBoundConstructor) AbstractBuild(hudson.model.AbstractBuild) BuildStepDescriptor(hudson.tasks.BuildStepDescriptor) BuildStepMonitor(hudson.tasks.BuildStepMonitor) QueryParameter(org.kohsuke.stapler.QueryParameter) StaplerRequest(org.kohsuke.stapler.StaplerRequest) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) Folder(com.cloudbees.hudson.plugins.folder.Folder) AncestorInPath(org.kohsuke.stapler.AncestorInPath) BuildListener(hudson.model.BuildListener) Item(hudson.model.Item) Extension(hudson.Extension) EnvVars(hudson.EnvVars) Path(java.nio.file.Path) Publisher(hudson.tasks.Publisher) Status(com.atlassian.jira.rest.client.api.domain.Status) TaskListener(hudson.model.TaskListener) ListBoxModel(hudson.util.ListBoxModel) Files(java.nio.file.Files) StatusCategory(com.atlassian.jira.rest.client.api.StatusCategory) FormValidation(hudson.util.FormValidation) BufferedWriter(java.io.BufferedWriter) Notifier(hudson.tasks.Notifier) Jenkins(jenkins.model.Jenkins) Launcher(hudson.Launcher) IOException(java.io.IOException) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) ItemGroup(hudson.model.ItemGroup) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) Paths(java.nio.file.Paths) AbstractProject(hudson.model.AbstractProject) Result(hudson.model.Result) JSONObject(net.sf.json.JSONObject) BufferedReader(java.io.BufferedReader) EnvVars(hudson.EnvVars) Issue(com.atlassian.jira.rest.client.api.domain.Issue)

Example 7 with Priority

use of com.atlassian.jira.rest.client.api.domain.Priority in project camel-spring-boot by apache.

the class UpdateIssueProducerTest method contextConfiguration.

@Bean
CamelContextConfiguration contextConfiguration() {
    return new CamelContextConfiguration() {

        @Override
        public void beforeApplicationStart(CamelContext context) {
            // get chance to mock camelContext/Registry
            jiraRestClientFactory = mock(JiraRestClientFactory.class);
            jiraClient = mock(JiraRestClient.class);
            issueRestClient = mock(IssueRestClient.class);
            metadataRestClient = mock(MetadataRestClient.class);
            when(jiraRestClientFactory.createWithBasicHttpAuthentication(any(), any(), any())).thenReturn(jiraClient);
            when(jiraClient.getIssueClient()).thenReturn(issueRestClient);
            when(jiraClient.getMetadataClient()).thenReturn(metadataRestClient);
            Map<Integer, IssueType> issueTypes = new HashMap<>();
            issueTypes.put(1, new IssueType(null, 1L, "Bug", false, null, null));
            issueTypes.put(2, new IssueType(null, 2L, "Task", false, null, null));
            Promise<Iterable<IssueType>> promiseIssueTypes = Promises.promise(issueTypes.values());
            when(metadataRestClient.getIssueTypes()).thenReturn(promiseIssueTypes);
            Map<Integer, Priority> issuePriorities = new HashMap<>();
            issuePriorities.put(1, new Priority(null, 1L, "High", null, null, null));
            issuePriorities.put(2, new Priority(null, 2L, "Low", null, null, null));
            Promise<Iterable<Priority>> promisePriorities = Promises.promise(issuePriorities.values());
            when(metadataRestClient.getPriorities()).thenReturn(promisePriorities);
            backendIssue = createIssue(11L);
            when(issueRestClient.updateIssue(anyString(), any(IssueInput.class))).then(inv -> {
                String issueKey = inv.getArgument(0);
                IssueInput issueInput = inv.getArgument(1);
                String summary = (String) issueInput.getField("summary").getValue();
                Integer issueTypeId = Integer.parseInt(getValue(issueInput, "issuetype", "id"));
                IssueType issueType = issueTypes.get(issueTypeId);
                String description = (String) issueInput.getField("description").getValue();
                Integer priorityId = Integer.parseInt(getValue(issueInput, "priority", "id"));
                BasicPriority priority = issuePriorities.get(priorityId);
                backendIssue = createIssue(11L, summary, issueKey, issueType, description, priority, userAssignee, null, null);
                BasicIssue basicIssue = new BasicIssue(backendIssue.getSelf(), backendIssue.getKey(), backendIssue.getId());
                return Promises.promise(basicIssue);
            });
            when(issueRestClient.getIssue(any())).then(inv -> Promises.promise(backendIssue));
            camelContext.getRegistry().bind(JIRA_REST_CLIENT_FACTORY, jiraRestClientFactory);
        }

        @Override
        public void afterApplicationStart(CamelContext camelContext) {
        // do nothing here
        }
    };
}
Also used : CamelContext(org.apache.camel.CamelContext) CamelContextConfiguration(org.apache.camel.spring.boot.CamelContextConfiguration) HashMap(java.util.HashMap) JiraRestClientFactory(com.atlassian.jira.rest.client.api.JiraRestClientFactory) MetadataRestClient(com.atlassian.jira.rest.client.api.MetadataRestClient) IssueType(com.atlassian.jira.rest.client.api.domain.IssueType) 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IssueInput(com.atlassian.jira.rest.client.api.domain.input.IssueInput) BasicIssue(com.atlassian.jira.rest.client.api.domain.BasicIssue) JiraRestClient(com.atlassian.jira.rest.client.api.JiraRestClient) BasicPriority(com.atlassian.jira.rest.client.api.domain.BasicPriority) Bean(org.springframework.context.annotation.Bean)

Example 8 with Priority

use of com.atlassian.jira.rest.client.api.domain.Priority in project camel-spring-boot by apache.

the class WatchUpdatesConsumerTest method singleChangeTest.

@Test
public void singleChangeTest() throws Exception {
    Issue issue = setPriority(issues.get(0), new Priority(null, 4L, "High", null, null, null));
    reset(searchRestClient);
    AtomicBoolean searched = new AtomicBoolean();
    when(searchRestClient.searchJql(any(), any(), any(), any())).then(invocation -> {
        if (!searched.get()) {
            issues.remove(0);
            issues.add(0, issue);
        }
        SearchResult result = new SearchResult(0, 50, 100, issues);
        return Promises.promise(result);
    });
    mockResult.expectedBodiesReceived(issue.getPriority());
    mockResult.expectedHeaderReceived(JiraConstants.ISSUE_CHANGED, "Priority");
    mockResult.expectedHeaderReceived(JiraConstants.ISSUE_KEY, "TST-1");
    mockResult.expectedMessageCount(1);
    mockResult.assertIsSatisfied(0);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Issue(com.atlassian.jira.rest.client.api.domain.Issue) Utils.createIssue(org.apache.camel.component.jira.springboot.test.Utils.createIssue) Priority(com.atlassian.jira.rest.client.api.domain.Priority) Utils.setPriority(org.apache.camel.component.jira.springboot.test.Utils.setPriority) SearchResult(com.atlassian.jira.rest.client.api.domain.SearchResult) CamelSpringBootTest(org.apache.camel.test.spring.junit5.CamelSpringBootTest) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Priority (com.atlassian.jira.rest.client.api.domain.Priority)8 Issue (com.atlassian.jira.rest.client.api.domain.Issue)4 IssueType (com.atlassian.jira.rest.client.api.domain.IssueType)4 IssueRestClient (com.atlassian.jira.rest.client.api.IssueRestClient)3 JiraRestClient (com.atlassian.jira.rest.client.api.JiraRestClient)3 BasicIssue (com.atlassian.jira.rest.client.api.domain.BasicIssue)3 BasicPriority (com.atlassian.jira.rest.client.api.domain.BasicPriority)3 IssueInput (com.atlassian.jira.rest.client.api.domain.input.IssueInput)3 JiraRestClientFactory (com.atlassian.jira.rest.client.api.JiraRestClientFactory)2 MetadataRestClient (com.atlassian.jira.rest.client.api.MetadataRestClient)2 SearchResult (com.atlassian.jira.rest.client.api.domain.SearchResult)2 Folder (com.cloudbees.hudson.plugins.folder.Folder)2 HashMap (java.util.HashMap)2 RestClientException (com.atlassian.jira.rest.client.api.RestClientException)1 SearchRestClient (com.atlassian.jira.rest.client.api.SearchRestClient)1 StatusCategory (com.atlassian.jira.rest.client.api.StatusCategory)1 BasicComponent (com.atlassian.jira.rest.client.api.domain.BasicComponent)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