You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2019/12/16 09:59:12 UTC

[sling-org-apache-sling-committer-cli] branch issue/SLING-8392 updated: SLING-8392 - Create sub-command to manage the Jira update when promoting a release

This is an automated email from the ASF dual-hosted git repository.

radu pushed a commit to branch issue/SLING-8392
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-committer-cli.git


The following commit(s) were added to refs/heads/issue/SLING-8392 by this push:
     new b757503  SLING-8392 - Create sub-command to manage the Jira update when promoting a release
b757503 is described below

commit b75750313a694b55fbaa38b6fdf62df1f3a0481b
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Mon Dec 16 10:58:55 2019 +0100

    SLING-8392 - Create sub-command to manage the Jira update when promoting a release
    
    * implemented the command for the CLI
    * made regex for filtering requests that need auth in mock jira implementation
    consistent with similar regexes
---
 .../cli/impl/release/CloseJiraVersionCommand.java  |  75 ---------------
 .../impl/release/ReleaseJiraVersionCommand.java    | 105 +++++++++++++++++++++
 .../org/apache/sling/cli/impl/jira/MockJira.java   |   2 +-
 3 files changed, 106 insertions(+), 76 deletions(-)

diff --git a/src/main/java/org/apache/sling/cli/impl/release/CloseJiraVersionCommand.java b/src/main/java/org/apache/sling/cli/impl/release/CloseJiraVersionCommand.java
deleted file mode 100644
index 8048436..0000000
--- a/src/main/java/org/apache/sling/cli/impl/release/CloseJiraVersionCommand.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements.  See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership.  The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License.  You may obtain a copy of the License at
- ~
- ~   http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied.  See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-package org.apache.sling.cli.impl.release;
-
-import org.apache.sling.cli.impl.Command;
-import org.apache.sling.cli.impl.jira.VersionClient;
-import org.apache.sling.cli.impl.nexus.RepositoryService;
-import org.apache.sling.cli.impl.nexus.StagingRepository;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Reference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import picocli.CommandLine;
-
-@Component(service = Command.class,
-           property = {
-                   Command.PROPERTY_NAME_COMMAND_GROUP + "=" + CloseJiraVersionCommand.GROUP,
-                   Command.PROPERTY_NAME_COMMAND_NAME + "=" + CloseJiraVersionCommand.NAME
-           }
-)
-@CommandLine.Command(
-        name = CloseJiraVersionCommand.NAME,
-        description = "Closes the found Jira versions by closing all their fixed issues and marking the versions as released with the " +
-                "current date.",
-        subcommands = CommandLine.HelpCommand.class
-)
-public class CloseJiraVersionCommand implements Command {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(CloseJiraVersionCommand.class);
-
-    static final String GROUP = "release";
-    static final String NAME = "close-jira-version";
-
-    @CommandLine.Option(names = {"-r", "--repository"}, description = "Nexus repository id", required = true)
-    private Integer repositoryId;
-
-    @Reference
-    private RepositoryService repositoryService;
-
-    @Reference
-    private VersionClient versionClient;
-
-    @CommandLine.Mixin
-    private ReusableCLIOptions reusableCLIOptions;
-
-    @Override
-    public void run() {
-        try {
-            StagingRepository repo = repositoryService.find(repositoryId);
-            for (Release release : repositoryService.getReleases(repo)) {
-//                versionClient.closeFixedIssues(release);
-                versionClient.release(release);
-            }
-        } catch (Exception e) {
-            LOGGER.warn("Failed executing command.", e);
-        }
-    }
-}
diff --git a/src/main/java/org/apache/sling/cli/impl/release/ReleaseJiraVersionCommand.java b/src/main/java/org/apache/sling/cli/impl/release/ReleaseJiraVersionCommand.java
new file mode 100644
index 0000000..cbdde72
--- /dev/null
+++ b/src/main/java/org/apache/sling/cli/impl/release/ReleaseJiraVersionCommand.java
@@ -0,0 +1,105 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.cli.impl.release;
+
+import java.util.List;
+import java.util.Set;
+
+import org.apache.sling.cli.impl.Command;
+import org.apache.sling.cli.impl.ExecutionMode;
+import org.apache.sling.cli.impl.InputOption;
+import org.apache.sling.cli.impl.UserInput;
+import org.apache.sling.cli.impl.jira.Issue;
+import org.apache.sling.cli.impl.jira.VersionClient;
+import org.apache.sling.cli.impl.nexus.RepositoryService;
+import org.apache.sling.cli.impl.nexus.StagingRepository;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import picocli.CommandLine;
+
+@Component(service = Command.class,
+           property = {
+                   Command.PROPERTY_NAME_COMMAND_GROUP + "=" + ReleaseJiraVersionCommand.GROUP,
+                   Command.PROPERTY_NAME_COMMAND_NAME + "=" + ReleaseJiraVersionCommand.NAME
+           }
+)
+@CommandLine.Command(
+        name = ReleaseJiraVersionCommand.NAME,
+        description = "The found Jira versions will be marked as released with the current date. All fixed issues will be closed. Before " +
+                "running this command make sure to execute " + CreateJiraVersionCommand.NAME + " in order to move any unresolved issues " +
+                "to the next version.",
+        subcommands = CommandLine.HelpCommand.class
+)
+public class ReleaseJiraVersionCommand implements Command {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ReleaseJiraVersionCommand.class);
+
+    static final String GROUP = "release";
+    static final String NAME = "release-jira-version";
+
+    @CommandLine.Option(names = {"-r", "--repository"}, description = "Nexus repository id", required = true)
+    private Integer repositoryId;
+
+    @Reference
+    private RepositoryService repositoryService;
+
+    @Reference
+    private VersionClient versionClient;
+
+    @CommandLine.Mixin
+    private ReusableCLIOptions reusableCLIOptions;
+
+    @Override
+    public void run() {
+        try {
+            StagingRepository repo = repositoryService.find(repositoryId);
+            Set<Release> releases = repositoryService.getReleases(repo);
+            ExecutionMode executionMode = reusableCLIOptions.executionMode;
+            LOGGER.info("The following Jira versions {} be released:{}", executionMode == ExecutionMode.DRY_RUN ? "would" : "will",
+                    System.lineSeparator());
+            for (Release release : releases) {
+                List<Issue> fixedIssues = versionClient.findFixedIssues(release);
+                LOGGER.info("{}:", release.getFullName());
+                fixedIssues.forEach(issue -> LOGGER.info("- {} - {}, Status: {}, Resolution: {}", issue.getKey(), issue.getSummary(),
+                        issue.getStatus(), issue.getResolution()));
+                LOGGER.info("");
+                boolean shouldRelease = false;
+                if (executionMode == ExecutionMode.INTERACTIVE) {
+                    InputOption answer = UserInput.yesNo(String.format("Should version %s be released?", release.getFullName()),
+                            InputOption.YES);
+                    shouldRelease = (answer == InputOption.YES);
+                } else if (executionMode == ExecutionMode.AUTO) {
+                    shouldRelease = true;
+                }
+                if (shouldRelease) {
+                    versionClient.release(release);
+                    LOGGER.info("{} was released:", release.getFullName());
+                    fixedIssues = versionClient.findFixedIssues(release);
+                    fixedIssues.forEach(issue -> LOGGER.info("- {} - {}, Status: {}, Resolution: {}", issue.getKey(), issue.getSummary(),
+                            issue.getStatus(), issue.getResolution()));
+                }
+            }
+        } catch (Exception e) {
+            LOGGER.warn("Failed executing command.", e);
+        }
+    }
+}
diff --git a/src/test/java/org/apache/sling/cli/impl/jira/MockJira.java b/src/test/java/org/apache/sling/cli/impl/jira/MockJira.java
index b67557a..95e4827 100644
--- a/src/test/java/org/apache/sling/cli/impl/jira/MockJira.java
+++ b/src/test/java/org/apache/sling/cli/impl/jira/MockJira.java
@@ -36,7 +36,7 @@ public class MockJira extends ExternalResource {
     
     static final String AUTH_USER = "asf-user";
     static final String AUTH_PWD = "asf-password";
-    private static final Set<Pattern> GET_PATHS_REQUIRING_AUTH = Set.of(Pattern.compile("/jira/rest/api/2/issue/\\d{1,10}/transitions"));
+    private static final Set<Pattern> GET_PATHS_REQUIRING_AUTH = Set.of(Pattern.compile("/jira/rest/api/2/issue/\\d+/transitions"));
     
     public static void main(String[] args) throws Throwable {