Пример #1
0
 // @Test
 public void testGetIssueByJql() {
   RemoteIssue[] issueByJql = lxitJiraService.getIssueByJql("project = DL1003  AND status = Open");
   for (RemoteIssue remoteIssue : issueByJql) {
     LxitJiraService.fixIssue(remoteIssue.getKey());
     System.out.println(
         "LxitJiraIssueServiceTest.testGetIssueByJql() key:" + remoteIssue.getKey());
   }
 }
Пример #2
0
 public static void main(String[] args) {
   LxitJiraService jirairaService = new LxitJiraService();
   RemoteIssue[] issueByJql = jirairaService.getIssueByJql("project = DLSIX  AND status = Open");
   for (RemoteIssue remoteIssue : issueByJql) {
     LxitJiraService.fixIssue(remoteIssue.getKey());
     System.out.println(
         "LxitJiraIssueServiceTest.testGetIssueByJql() key:" + remoteIssue.getKey());
   }
 }
Пример #3
0
  @Test
  public void shouldCollectIssuesByPriority() throws Exception {
    Filter filter = new Filter(null, 1l, null, null, null, null, null, null, false);
    JiraSoapService jiraSoapService = mock(JiraSoapService.class);

    JiraSoapSession soapSession = mock(JiraSoapSession.class);
    when(soapSession.getJiraSoapService()).thenReturn(jiraSoapService);

    JiraSoapServiceWrapper wrapper = new JiraSoapServiceWrapper(jiraSoapService, null, settings);
    when(soapSession.getJiraService(Matchers.<RuleFinder>any(), Matchers.<Settings>any()))
        .thenReturn(wrapper);

    RemoteIssue issue1 = new RemoteIssue();
    issue1.setPriority("1");
    issue1.setId("1");
    RemoteIssue issue2 = new RemoteIssue();
    issue2.setPriority("1");
    issue2.setId("2");
    RemoteIssue issue3 = new RemoteIssue();
    issue3.setPriority("2");
    issue3.setId("3");
    when(jiraSoapService.getIssuesFromFilter("token", "1"))
        .thenReturn(new RemoteIssue[] {issue1, issue2, issue3});

    Map<Long, Integer> foundIssues = sensor.collectIssuesByPriority(wrapper, "token", filter);
    assertThat(foundIssues.size()).isEqualTo(2);
    assertThat(foundIssues.get(1l)).isEqualTo(2);
    assertThat(foundIssues.get(2l)).isEqualTo(1);
  }
Пример #4
0
 private boolean issueIsReleased(final RemoteIssue issue) {
   final RemoteVersion[] fixVersions = issue.getFixVersions();
   for (int i = 0; i < fixVersions.length; i++) {
     if (isReleasedWithVersionNumber(fixVersions[i])) {
       return true;
     }
   }
   return false;
 }
  @Test
  public void shouldInitRemoteIssueWithComponent() throws Exception {
    // Given that
    settings.setProperty(JiraConstants.JIRA_ISSUE_COMPONENT_ID, "123");
    RemoteIssue expectedIssue = new RemoteIssue();
    expectedIssue.setProject("TEST");
    expectedIssue.setType("3");
    expectedIssue.setPriority("4");
    expectedIssue.setSummary("Sonar Issue #ABCD - Avoid cycle between java packages");
    expectedIssue.setDescription(
        "Issue detail:\n{quote}\nThe Cyclomatic Complexity of this method is 14 which is greater than 10 authorized.\n"
            + "{quote}\n\n\nCheck it on Sonar: http://my.sonar.com/issue/show/ABCD");
    expectedIssue.setComponents(new RemoteComponent[] {new RemoteComponent("123", null)});

    // Verify
    RemoteIssue returnedIssue = jiraIssueCreator.initRemoteIssue(sonarIssue, settings, "");

    assertThat(returnedIssue).isEqualTo(expectedIssue);
  }
  @Test
  public void shouldInitRemoteIssueWithoutName() throws Exception {
    // Given that
    when(ruleFinder.findByKey(RuleKey.of("squid", "CycleBetweenPackages")))
        .thenReturn(org.sonar.api.rules.Rule.create().setName(null));

    RemoteIssue expectedIssue = new RemoteIssue();
    expectedIssue.setProject("TEST");
    expectedIssue.setType("3");
    expectedIssue.setPriority("4");
    expectedIssue.setSummary("Sonar Issue #ABCD");
    expectedIssue.setDescription(
        "Issue detail:\n{quote}\nThe Cyclomatic Complexity of this method is 14 which is greater than 10 authorized.\n"
            + "{quote}\n\n\nCheck it on Sonar: http://my.sonar.com/issue/show/ABCD");

    // Verify
    RemoteIssue returnedIssue = jiraIssueCreator.initRemoteIssue(sonarIssue, settings, "");

    assertThat(returnedIssue.getSummary()).isEqualTo(expectedIssue.getSummary());
    assertThat(returnedIssue.getDescription()).isEqualTo(expectedIssue.getDescription());
    assertThat(returnedIssue).isEqualTo(expectedIssue);
  }
 /** {@inheritDoc} */
 @Override
 public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
     throws InterruptedException, IOException {
   JIRAClient client = null;
   // Get the previous JIRA Build Action, if any.
   Run<?, ?> prevBuild = build.getPreviousBuild();
   JIRABuildResultReportAction buildAction = null;
   if (prevBuild != null) {
     buildAction = prevBuild.getAction(JIRABuildResultReportAction.class);
   }
   try {
     client = getSite().createClient();
     if (build.getResult().isWorseThan(Result.SUCCESS)) {
       String issueKey = null;
       if (buildAction != null
           && StringUtils.isNotBlank(buildAction.raisedIssueKey)
           && !buildAction.resolved) {
         // Oke the previous build also failed and has an Issue linked to it.
         // So relink that issue also to this build
         issueKey = client.updateIssue(build, buildAction.raisedIssueKey);
       } else {
         issueKey =
             client.createIssue(build, projectKey, issueType, issuePriority, assignToBuildBreaker);
       }
       build.addAction(new JIRABuildResultReportAction(build, issueKey, false));
       listener.getLogger().println("JBRR: Raised build failure issue: " + issueKey);
     } else if (autoClose && build.getResult().isBetterOrEqualTo(Result.SUCCESS)) {
       // Auto close the previously raised issues, if any
       if (buildAction != null) {
         RemoteIssue issue = client.getIssue(buildAction);
         if (issue == null || issue.getKey() == null) {
           listener
               .getLogger()
               .println(
                   "WARN: Failed to automatically close issue: Unable to locate issue "
                       + buildAction.raisedIssueKey
                       + " in JIRA site "
                       + getSite().name);
         } else if (client.canCloseIssue(issue)) {
           if (client.closeIssue(issue, build)) {
             build.addAction(new JIRABuildResultReportAction(build, issue.getKey(), true));
             listener
                 .getLogger()
                 .println(
                     "INFO: Closed issue "
                         + issue.getKey()
                         + " using action: "
                         + getSite().getCloseActionName());
           } else {
             listener
                 .getLogger()
                 .println("WARN: Failed to automatically close issue: " + issue.getKey());
           }
         }
       }
     }
   } catch (AxisFault e) {
     listener.error("JBRR: " + e.getFaultString());
   } catch (ServiceException e) {
     listener.error("JBRR: " + e.getMessage());
   } catch (MalformedURLException e) {
     listener.error("JBRR: Invalid JIRA URL configured");
   } finally {
     if (client != null) {
       client.logout();
     }
   }
   return true;
 }