Skip to content

Commit c0cbfc8

Browse files
committed
fixes #137 add delete branch task and update configuration for service.yml
1 parent 642aa50 commit c0cbfc8

File tree

31 files changed

+575
-23
lines changed

31 files changed

+575
-23
lines changed

bot-cli/src/main/resources/config/regex-replace.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ checkout:
3131
- [email protected]:networknt/light-bot-config.git
3232
- [email protected]:networknt/light-config-test.git
3333
- [email protected]:networknt/light-bot.git
34-
- [email protected]:networknt/light-config-server.git
34+
- [email protected]:lightapi/light-config-server.git
3535
- [email protected]:networknt/microservices-framework-benchmark.git
3636
- [email protected]:networknt/model-config.git
3737
- [email protected]:networknt/light-portal.git

bot-cli/src/main/resources/config/release-maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ checkout:
3535
- [email protected]:networknt/light-bot-config.git
3636
- [email protected]:networknt/light-config-test.git
3737
- [email protected]:networknt/light-bot.git
38-
- [email protected]:networknt/light-config-server.git
38+
- [email protected]:lightapi/light-config-server.git
3939
- [email protected]:networknt/microservices-framework-benchmark.git
4040
- [email protected]:networknt/model-config.git
4141
- [email protected]:networknt/light-portal.git

bot-cli/src/main/resources/config/service.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
singletons:
33
# Executor to CommandExecutor binding
44
- com.networknt.bot.core.Executor:
5-
- com.networknt.bot.core.CommandExecutor
5+
- com.networknt.bot.core.FasterRollingCommandExecutor
66
- com.networknt.bot.core.Command:
77
- com.networknt.bot.develop.DevelopBuildTask
88
- com.networknt.bot.version.VersionUpgradeTask
@@ -11,4 +11,5 @@ singletons:
1111
- com.networknt.bot.regex.replace.RegexReplaceTask
1212
- com.networknt.bot.branch.CreateBranchTask
1313
- com.networknt.bot.branch.MergeBranchTask
14+
- com.networknt.bot.branch.DeleteBranchTask
1415
- com.networknt.bot.sync.SyncGitRepoTask

exec-core/src/main/java/com/networknt/bot/core/CommandExecutor.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
import java.util.List;
1212
import java.util.Map;
1313

14-
/**
15-
* @deprecated
16-
*/
1714
public abstract class CommandExecutor implements Executor {
1815
static final Logger logger = LoggerFactory.getLogger(CommandExecutor.class);
1916

exec-core/src/main/java/com/networknt/bot/core/Constants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,7 @@ public class Constants {
120120
public static final String EXTERNAL_REPO = "external_repo";
121121
public static final String INTERNAL_REPO = "internal_repo";
122122

123+
// delete-branch
124+
public static final String SKIP_LOCAL = "skip_local";
125+
public static final String SKIP_REMOTE = "skip_remote";
123126
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.networknt.bot.core.cmd;
2+
3+
import com.networknt.bot.core.Command;
4+
import com.networknt.bot.core.Executor;
5+
import com.networknt.service.SingletonServiceFactory;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import java.io.IOException;
10+
import java.nio.file.Path;
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
/**
15+
* This command is to delete a local branch in the workspace if it exists.
16+
*/
17+
public class DeleteLocalBranchCmd implements Command {
18+
private static final Logger logger = LoggerFactory.getLogger(DeleteLocalBranchCmd.class);
19+
private final Executor executor = SingletonServiceFactory.getBean(Executor.class);
20+
private final Path rPath;
21+
private final String branch;
22+
23+
public DeleteLocalBranchCmd(Path rPath, String branch) {
24+
this.rPath = rPath;
25+
this.branch = branch;
26+
}
27+
28+
@Override
29+
public int execute() throws IOException, InterruptedException {
30+
int result;
31+
// create a branch from the current branch
32+
List<String> commands = new ArrayList<>();
33+
34+
commands.add("bash");
35+
commands.add("-c");
36+
commands.add("if git show-ref --verify --quiet refs/heads/" + branch + "; then git branch -d " + branch + "; else echo 'Branch " + branch + " does not exist'; fi");
37+
logger.info("Checking if branch {} exists and deleting it for {}", branch, rPath);
38+
result = executor.execute(commands, rPath.toFile());
39+
String stdout = executor.getStdout();
40+
if(stdout != null && !stdout.isEmpty()) logger.debug(stdout);
41+
String stderr = executor.getStderr();
42+
if(stderr != null && !stderr.isEmpty()) logger.info(stderr);
43+
return result;
44+
}
45+
46+
@Override
47+
public String getName() {
48+
return "DeleteLocalBranch";
49+
}
50+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.networknt.bot.core.cmd;
2+
3+
import com.networknt.bot.core.Command;
4+
import com.networknt.bot.core.Executor;
5+
import com.networknt.service.SingletonServiceFactory;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
9+
import java.io.IOException;
10+
import java.nio.file.Path;
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
/**
15+
* This command is to delete a remote branch in the workspace.
16+
*
17+
*/
18+
public class DeleteRemoteBranchCmd implements Command {
19+
private static final Logger logger = LoggerFactory.getLogger(DeleteRemoteBranchCmd.class);
20+
private final Executor executor = SingletonServiceFactory.getBean(Executor.class);
21+
private final Path rPath;
22+
private final String branch;
23+
24+
public DeleteRemoteBranchCmd(Path rPath, String branch) {
25+
this.rPath = rPath;
26+
this.branch = branch;
27+
}
28+
29+
@Override
30+
public int execute() throws IOException, InterruptedException {
31+
int result;
32+
// create a branch from the current branch
33+
List<String> commands = new ArrayList<>();
34+
commands.add("bash");
35+
commands.add("-c");
36+
37+
commands.add("git push -d origin " + branch);
38+
logger.info("git push -d origin {} for {}", branch, rPath);
39+
40+
result = executor.execute(commands, rPath.toFile());
41+
String stdout = executor.getStdout();
42+
if(stdout != null && !stdout.isEmpty()) logger.debug(stdout);
43+
String stderr = executor.getStderr();
44+
if(stderr != null && !stderr.isEmpty()) logger.info(stderr);
45+
return result;
46+
}
47+
48+
@Override
49+
public String getName() {
50+
return "DeleteRemoteBranch";
51+
}
52+
}

exec-create-branch/src/test/java/com/networknt/bot/branch/CreateBranchTaskTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.networknt.bot.branch;
22

33
import org.junit.Assert;
4+
import org.junit.Ignore;
45
import org.junit.Test;
56

67
import java.io.IOException;
78

89
public class CreateBranchTaskTest {
9-
//@Test
10+
@Test
11+
@Ignore
1012
public void testCreateBranch() throws IOException, InterruptedException {
1113
CreateBranchTask cmd = new CreateBranchTask();
1214
int result = cmd.execute();
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# This task is used to create a new branch from an existing branch or a tag.
22
# Workspace that is used for this operation. Most of time, this is done on local.
3-
workspace: createbranch
3+
workspace: create-branch-test
44
# The new branch name that is going to be created
5-
branch: 1.6.x
5+
branch: patch
66
# If the new branch is created from a tag
7-
from_tag: false
7+
from_tag: true
88
# The original tag to create a new branch if from_tag is true.
9-
tag: 1.5.32
9+
tag: 2.1.37
1010
# You can skip checkout if you are sure that the code in workspace are the latest and
1111
# you just want to repeat the create branch process due to some environmental issue before.
1212
skip_checkout: false
@@ -16,7 +16,7 @@ skip_branch: false
1616
skip_push: true
1717
# clone and switch to the branch specified in checkout step.
1818
checkout:
19-
- branch: develop
19+
- branch: master
2020
repository:
2121
- [email protected]:networknt/json-overlay.git
2222
- [email protected]:networknt/openapi-parser.git

exec-create-branch/src/test/resources/config/service.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
singletons:
33
# Executor to CommandExecutor binding
44
- com.networknt.bot.core.Executor:
5-
- com.networknt.bot.core.CommandExecutor
5+
- com.networknt.bot.core.FasterRollingCommandExecutor
66
- com.networknt.bot.core.Command:
77
- com.networknt.bot.branch.CreateBranchTask

0 commit comments

Comments
 (0)