GitForkCmd extends BaseCommand { @Override public ICmdResult execute() { CmdResult result = new CmdResult(); String sourceOrganization = getSourceOrganization(m_gitUrl); String sourceRepo = getSourceRepo(m_gitUrl); String forkUrl = Config.getInstance().getGitAPIUrl() + sourceOrganization + "/" + sourceRepo + "/forks"; try { ResteasyClient client = new ResteasyClientBuilder().build(); client.register(new BasicAuthentication(m_userName, m_password)); client.register(new AgentHeadersRequestFilter(m_userName)); ResteasyWebTarget target = client.target(forkUrl); Organization o = new Organization(m_organization); Response response = target.request().post(Entity.entity(o, "application/json")); if ((response.getStatus() == 201) || (response.getStatus() == 202)) { String resStr = response.readEntity(String.class); JSONObject jsonObject = new JSONObject(resStr); try { m_forkedGitUrl = jsonObject.get("html_url").toString(); } catch (JSONException e) { e.printStackTrace(); result.setException(e); } result.setMessage("OK"); } else { System.err.println("Unexpected response status:" + response.getStatus()); throw new RuntimeException("Unexpected response status:" + response.getStatus() + " " + response.readEntity(String.class)); } if (result.getException() == null) { waitForkComplete(client, forkUrl); } } catch (Exception ex) { result.setException(ex); } return result; } GitForkCmd(String name); @Override ICmdResult execute();  }
@Test public void testFork() { GitForkCmd task = new GitForkCmd("fork1"); Map<String, Object> attrs = new HashMap<>(); String organization = "UpgradeTest"; Config gitconfig = Config.getInstance(); gitconfig.setGitAPIUrl("https: gitconfig.setOrganization("UpgradeTest"); attrs.put("fork1.gitUrl", "https: attrs.put("fork1.username", "platformupgradeservice"); attrs.put("fork1.password", "dummy"); attrs.put("fork1.organization", organization); CmdManager manager = CmdManagerFactory.create(attrs); manager.addCmd(task); manager.execute(); Assert.assertTrue(manager.isDone()); Assert.assertEquals(task, manager.getAllCmds().get(0)); System.out.println("result:" + manager.getResults()); Assert.assertTrue(manager.isSuccess()); }