com.jcabi.github.Coordinates Java Examples

The following examples show how to use com.jcabi.github.Coordinates. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpringCloudGithubIssuesTests.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void should_file_an_issue_for_release_version_when_updating_startspringio()
		throws IOException {
	setupStartSpringIo();
	CustomGithubIssues issues = new SpringCloudGithubIssues(github, properties);
	properties.getPom().setBranch("vEdgware.RELEASE");

	issues.fileIssueInStartSpringIo(
			new Projects(new ProjectVersion("spring-cloud-foo", "1.0.0.RELEASE"),
					new ProjectVersion("spring-cloud-build", "2.0.0.RELEASE"),
					new ProjectVersion("bar", "2.0.0.RELEASE"),
					new ProjectVersion("baz", "3.0.0.RELEASE"),
					new ProjectVersion("spring-boot", "1.2.3.RELEASE")),
			new ProjectVersion("sc-release", "Edgware.RELEASE"));

	Issue issue = this.github.repos()
			.get(new Coordinates.Simple("spring-io", "start.spring.io")).issues()
			.get(1);
	then(issue.exists()).isTrue();
	Issue.Smart smartIssue = new Issue.Smart(issue);
	then(smartIssue.title()).isEqualTo("Upgrade to Spring Cloud Edgware.RELEASE");
	then(smartIssue.body()).contains(
			"Release train [spring-cloud-release] in version [Edgware.RELEASE] released with the Spring Boot version [`1.2.3.RELEASE`]");
}
 
Example #2
Source File: GithubIssueFiler.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
private void fileAGithubIssue(String user, String repo, String issueTitle,
		String issueText) {
	Repo ghRepo = this.github.repos().get(new Coordinates.Simple(user, repo));
	// check if the issue is not already there
	boolean issueAlreadyFiled = issueAlreadyFiled(ghRepo, issueTitle);
	if (issueAlreadyFiled) {
		log.info("Issue already filed, will not do that again");
		return;
	}
	try {
		int number = ghRepo.issues().create(issueTitle, issueText).number();
		log.info(
				"Successfully created an issue with "
						+ "title [{}] for the [{}/{}] GitHub repository" + number,
				issueTitle, user, repo);
	}
	catch (IOException e) {
		log.error("Exception occurred while trying to create the issue in guides", e);
	}
}
 
Example #3
Source File: SpringCloudGithubIssuesTests.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void should_file_an_issue_for_release_version() throws IOException {
	CustomGithubIssues issues = new SpringCloudGithubIssues(github, properties);
	properties.getPom().setBranch("vEdgware.RELEASE");

	issues.fileIssueInSpringGuides(
			new Projects(new ProjectVersion("spring-cloud-foo", "1.0.0.RELEASE"),
					new ProjectVersion("spring-cloud-build", "2.0.0.RELEASE"),
					new ProjectVersion("bar", "2.0.0.RELEASE"),
					new ProjectVersion("baz", "3.0.0.RELEASE")),
			new ProjectVersion("sc-release", "Edgware.RELEASE"));

	Issue issue = this.github.repos()
			.get(new Coordinates.Simple("spring-guides", "getting-started-guides"))
			.issues().get(1);
	then(issue.exists()).isTrue();
	Issue.Smart smartIssue = new Issue.Smart(issue);
	then(smartIssue.title()).isEqualTo("Upgrade to Spring Cloud Edgware.RELEASE");
	then(smartIssue.body()).contains(
			"Release train [spring-cloud-release] in version [Edgware.RELEASE] released with the following projects")
			.contains("spring-cloud-foo : `1.0.0.RELEASE`")
			.contains("bar : `2.0.0.RELEASE`").contains("baz : `3.0.0.RELEASE`");
}
 
Example #4
Source File: LastCommentTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Mock an issue on Github.
 * @return 2 Issues: 1 from the commander's Github (where the comments
 * are posted) and 1 from the agent's Github (where comments are checked)
 * @throws IOException If something goes wrong.
 */
private Issue[] mockIssue() throws IOException {
    MkStorage storage = new MkStorage.InFile();
    Github commanderGithub = new MkGithub(storage, "amihaiemil");
    commanderGithub.users().self().emails().add(Arrays.asList("[email protected]"));
    Github agentGithub = new MkGithub(storage, "charlesmike");
    
    RepoCreate repoCreate = new RepoCreate("amihaiemil.github.io", false);
    commanderGithub.repos().create(repoCreate);
    Issue[] issues = new Issue[2];
    Coordinates repoCoordinates = new Coordinates.Simple("amihaiemil", "amihaiemil.github.io");
    Issue authorsIssue = commanderGithub.repos().get(repoCoordinates).issues().create("Test issue for commands", "test body");
    Issue agentsIssue = agentGithub.repos().get(repoCoordinates).issues().get(authorsIssue.number());
    issues[0] = authorsIssue;
    issues[1] = agentsIssue;
    
    return issues;
}
 
Example #5
Source File: TextReplyTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Mock a Github command where the agent is mentioned.
 * @return The created Command.
 * @throws IOException If something goes wrong.
 */
public Command mockCommand(String msg) throws IOException {
    Github gh = new MkGithub("amihaiemil");
    RepoCreate repoCreate = new RepoCreate("amihaiemil.github.io", false);
    gh.repos().create(repoCreate);
    Issue issue = gh.repos().get(
                      new Coordinates.Simple("amihaiemil", "amihaiemil.github.io")
                  ).issues().create("Test issue for commands", "test body");
    Comment c = issue.comments().post(msg);
    
    Command com = Mockito.mock(Command.class);

    Mockito.when(com.json()).thenReturn(c.json());
    Mockito.when(com.issue()).thenReturn(issue);
     
    return com;
}
 
Example #6
Source File: CachingGithubTests.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
@Test
void should_not_cache_calls_for_different_coordinates() {
	Repos repos = mock(Repos.class);
	CachingRepos cachingRepos = new CachingRepos(repos);
	Coordinates.Simple simple1 = new Coordinates.Simple("foo", "bar1");
	Coordinates.Simple simple2 = new Coordinates.Simple("foo", "bar2");
	Coordinates.Simple simple3 = new Coordinates.Simple("foo", "bar3");

	cachingRepos.get(simple1);
	cachingRepos.get(simple2);
	cachingRepos.get(simple3);

	verify(repos).get(simple1);
	verify(repos).get(simple2);
	verify(repos).get(simple3);
}
 
Example #7
Source File: CachingGithubTests.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
@Test
void should_not_cache_calls_for_different_coordinates_for_repo() {
	Repo repo1 = mock(Repo.class);
	given(repo1.coordinates()).willReturn(new Coordinates.Simple("foo", "bar"));
	Repo repo2 = mock(Repo.class);
	given(repo2.coordinates()).willReturn(new Coordinates.Simple("foo", "bar"));
	Repo repo3 = mock(Repo.class);
	given(repo3.coordinates()).willReturn(new Coordinates.Simple("foo", "bar"));

	new CachingRepo(repo1).coordinates();
	new CachingRepo(repo2).coordinates();
	new CachingRepo(repo3).coordinates();

	verify(repo1).coordinates();
	verify(repo2).coordinates();
	verify(repo3).coordinates();
}
 
Example #8
Source File: InitializrSpringCloudInfoServiceTests.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void getMilestoneDueDateTest() throws Exception {
	RestTemplate rest = mock(RestTemplate.class);
	Github github = mock(Github.class);
	GithubPomReader githubPomReader = mock(GithubPomReader.class);
	Repos repos = mock(Repos.class);
	Repo repo = mock(Repo.class);
	Milestones milestones = mock(Milestones.class);
	Iterable iterable = buildMilestonesIterable();
	doReturn(iterable).when(milestones).iterate(any(Map.class));
	doReturn(milestones).when(repo).milestones();
	doReturn(repo).when(repos).get(any(Coordinates.class));
	doReturn(repos).when(github).repos();
	InitializrSpringCloudInfoService service = spy(
			new InitializrSpringCloudInfoService(rest, github, githubPomReader));
	assertThat(service.getMilestoneDueDate("Finchley.SR4"),
			Matchers.equalTo(new SpringCloudInfoService.Milestone("No Due Date")));
	assertThat(service.getMilestoneDueDate("Hoxton.RELEASE"),
			Matchers.equalTo(new SpringCloudInfoService.Milestone("2019-07-31")));
}
 
Example #9
Source File: InitializrSpringCloudInfoServiceTests.java    From spring-cloud-release-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void getMilestonesTest() throws Exception {
	RestTemplate rest = mock(RestTemplate.class);
	Github github = mock(Github.class);
	GithubPomReader githubPomReader = mock(GithubPomReader.class);
	Repos repos = mock(Repos.class);
	Repo repo = mock(Repo.class);
	Milestones milestones = mock(Milestones.class);
	Iterable iterable = buildMilestonesIterable();
	doReturn(iterable).when(milestones).iterate(any(Map.class));
	doReturn(milestones).when(repo).milestones();
	doReturn(repo).when(repos).get(any(Coordinates.class));
	doReturn(repos).when(github).repos();
	InitializrSpringCloudInfoService service = spy(
			new InitializrSpringCloudInfoService(rest, github, githubPomReader));
	assertThat(service.getMilestones(), Matchers.equalTo(milestoneStrings.keySet()));

}
 
Example #10
Source File: GithubFacadeBuilder.java    From sputnik with Apache License 2.0 5 votes vote down vote up
@NotNull
public GithubFacade build(Configuration configuration) {

    Patchset patchset = PatchsetBuilder.build(configuration);

    String oAuthKey = configuration.getProperty(GeneralOption.GITHUB_API_KEY);
    Github github = new RtGithub(
            new RtGithub(oAuthKey)
                    .entry()
                    .through(RetryWire.class)
    );

    Repo repo = github.repos().get(new Coordinates.Simple(patchset.getProjectPath()));
    return new GithubFacade(repo, patchset);
}
 
Example #11
Source File: ActionTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates an Issue with the given command.
 * @param commander Author of the comment;
 * @param command The comment's body;
 * @return Github issue
 */
public Issue githubIssue(String commander, String command) throws Exception {
    MkStorage storage = new MkStorage.InFile();
    Github commanderGh = new MkGithub(storage, commander);
    RepoCreate repoCreate = new RepoCreate(commander + ".github.io", false);
    commanderGh.repos().create(repoCreate);
    Coordinates repoCoordinates = new Coordinates.Simple(commander, commander + ".github.io");
    Issue issue = commanderGh.repos().get(repoCoordinates).issues().create("Test issue for commands", "test body");
    issue.comments().post(command);
    Github agentGh = new MkGithub(storage, "charlesmike");
    return agentGh.repos().get(repoCoordinates).issues().get(issue.number());
    
}
 
Example #12
Source File: SendReplyTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Mock a command.
 * @return The created Command.
 * @throws IOException If something goes wrong.
 */
public Command mockCommand() throws IOException {
    Github gh = new MkGithub("amihaiemil");
    RepoCreate repoCreate = new RepoCreate("amihaiemil.github.io", false);
    gh.repos().create(repoCreate);
    Issue issue = gh.repos().get(
                      new Coordinates.Simple("amihaiemil", "amihaiemil.github.io")
                  ).issues().create("Test issue for commands", "test body");
    Command com = Mockito.mock(Command.class);
    Mockito.when(com.issue()).thenReturn(issue);
    Mockito.when(com.json()).thenReturn(Json.createObjectBuilder().add("body", "@charlesmike hello").build());
    return com;
}
 
Example #13
Source File: StepsTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Mock a command.
 * @return The created Command.
 * @throws IOException If something goes wrong.
 */
private Command mockCommand() throws IOException {
    Github gh = new MkGithub("amihaiemil");
    RepoCreate repoCreate = new RepoCreate("amihaiemil.github.io", false);
    gh.repos().create(repoCreate);
    Issue issue = gh.repos().get(
                      new Coordinates.Simple("amihaiemil", "amihaiemil.github.io")
                  ).issues().create("Test issue for commands", "test body");
    Command com = Mockito.mock(Command.class);
    Mockito.when(com.language()).thenReturn(new English());
    Mockito.when(com.authorLogin()).thenReturn("amihaiemil");
    Mockito.when(com.issue()).thenReturn(issue);
    Mockito.when(com.json()).thenReturn(Json.createObjectBuilder().add("body", "@charlesmike mock command").build());
    return com;
}
 
Example #14
Source File: ErrorReplyTestCase.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Mock a Github issue.
 * @return The created Issue.
 * @throws IOException If something goes wrong.
 */
public Issue mockIssue() throws IOException {
    Github gh = new MkGithub("amihaiemil");
    RepoCreate repoCreate = new RepoCreate("amihaiemil.github.io", false);
    gh.repos().create(repoCreate);
    return gh.repos().get(
                      new Coordinates.Simple("amihaiemil", "amihaiemil.github.io")
                  ).issues().create("Test issue for commands", "test body");
}
 
Example #15
Source File: NotificationsResource.java    From charles-rest with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Handles notifications, starts one action thread for each of them.
 * @param notifications List of notifications.
 * @return true if actions were started successfully; false otherwise.
 */
private boolean handleNotifications(final Notifications notifications) {
    String authToken = System.getProperty("github.auth.token");
    if(authToken == null || authToken.isEmpty()) {
        LOG.error("Missing github.auth.token. Please specify a Github api access token!");
        return false;
    } else {
        Github gh = new RtGithub(
            new RtGithub(
                authToken
            ).entry().through(RetryWire.class)
        );
        try {
            for(final Notification notification : notifications) {
                this.actions.take(
                    new Action(
                        gh.repos().get(
                            new Coordinates.Simple(notification.repoFullName())
                        ).issues().get(notification.issueNumber())
                    )
                );
            }
            return true;
        } catch (IOException ex) {
            LOG.error("IOException while getting the Issue from Github API");
            return false;
        }
    }
}
 
Example #16
Source File: SpringCloudRelease.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private Iterable<com.jcabi.github.Milestone> getMilestonesFromGithub() {
	Map<String, String> params = new HashMap<>();
	params.put("state", "open");
	return github.repos()
			.get(new Coordinates.Simple(SPRING_CLOUD_RELEASE_COORDINATES))
			.milestones().iterate(params);
}
 
Example #17
Source File: CachingGithubTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Test
void should_coordinates_only_once_for_same_repo() {
	Repo repo = mock(Repo.class);
	given(repo.coordinates()).willReturn(new Coordinates.Simple("foo", "bar"));
	CachingRepo cachingRepo = new CachingRepo(repo);

	cachingRepo.coordinates();
	cachingRepo.coordinates();
	cachingRepo.coordinates();

	verify(repo, only()).coordinates();
}
 
Example #18
Source File: CachingGithubTests.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
@Test
void should_get_repo_only_once_for_same_coordinates() {
	Repos repos = mock(Repos.class);
	CachingRepos cachingRepos = new CachingRepos(repos);
	Coordinates.Simple simple = new Coordinates.Simple("foo", "bar");

	cachingRepos.get(simple);
	cachingRepos.get(simple);
	cachingRepos.get(simple);

	verify(repos, only()).get(simple);
}
 
Example #19
Source File: GithubMilestones.java    From spring-cloud-release-tools with Apache License 2.0 5 votes vote down vote up
private Iterable<Milestone> getMilestones(ProjectVersion version,
		Map<String, String> map) {
	try {
		return this.github.repos()
				.get(new Coordinates.Simple(org(), version.projectName)).milestones()
				.iterate(map);
	}
	catch (AssertionError e) {
		log.error("Exception occurred while trying to fetch milestones", e);
		return new ArrayList<>();
	}
}
 
Example #20
Source File: CachingGithub.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
@Override
public Coordinates coordinates() {
	return (Coordinates) CACHE.computeIfAbsent(
			new RepoKey(this.delegate, "coordinates"),
			s -> this.delegate.coordinates());
}
 
Example #21
Source File: CachingGithub.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
@Override
public void remove(Coordinates coordinates) throws IOException {
	this.delegate.remove(coordinates);
}
 
Example #22
Source File: CachingGithub.java    From spring-cloud-release-tools with Apache License 2.0 4 votes vote down vote up
@Override
public Repo get(Coordinates coordinates) {
	return CACHE.computeIfAbsent(coordinates,
			o -> new CachingRepo(this.delegate.get(coordinates)));
}