NCoop
NCoop

Reputation: 331

How do you add outside collaborators to repositories in your organization using Github Java API?

I am trying to automate the process of instructors setting up an organization with repositories for their students. The repositories need to have a user be added as a collaborator because a continuous delivery server uses that user to make updates to the student repositories. The issue I am having is sending an invite to the user using the Github Java API. Here is the current code I am trying to use:

GHCreateRepositoryBuilder builder = this.organization.createRepository(this.prefix + i);
GHRepository repo = builder.create();
repo.addCollaborators(github.getUser("vcdep"));
repositories.add(repo);

The above code successfully creates the repository in the organization, but throws the following IO exception when the addCollaborators method is called:

Caused by: java.io.IOException: Operation not applicable to a repository owned by someone else: TestOrganizationForDevOps
at org.kohsuke.github.GHRepository.verifyMine(GHRepository.java:1097)
at org.kohsuke.github.GHRepository.modifyCollaborators(GHRepository.java:507)
at org.kohsuke.github.GHRepository.addCollaborators(GHRepository.java:495)
at org.kohsuke.github.GHRepository.addCollaborators(GHRepository.java:491)
at wizard.GitHubController.createRepos(GitHubController.java:94)
at wizard.Controller.onButtonClickedFinish(Controller.java:260)
... 58 more

I have looked at other posts here, however, most of them talk about creating a team by inviting the users and then adding that team to the repository. But I am unable to do that because the user that must be attached to the repositories needs to automatically accept the invites and I already have a system in place that does that but only for repository invites, not team invites. I also looked at the Github Java API repository's issue tracker and haven't found any similar to mine.

I thought I did not have the correct permissions at first but I am using a personal token from the account that owns the organization and that token has full privileges and I successfully authenticate using the Github Java API since the repository is created. I also tried adding the user as a member to the Github organization and then run the above code to see if that would help but had the same error appear. I have looked at the docs for both the Github Java API and just the Github API itself and cannot see why the above is not working and I am wondering if it is an error or expected behavior. If any of you have any idea how to fix this I would really appreciate your help.

Also, I am using Maven to handle installing the GitHub API by Kohsuke. Here is a snippet from my pom.xml that handles the dependency

<dependency>
    <groupId>org.kohsuke</groupId>
    <artifactId>github-api</artifactId>
    <version>1.80</version>
</dependency>

Thank you for your time.

Upvotes: 0

Views: 589

Answers (1)

J.Gerbershagen
J.Gerbershagen

Reputation: 316

Are you using the source code from kohsuke? In this source code the method 'verifyMine' doesn't exists. This behaviour is perhaps caused because using a fork.

Upvotes: 0

Related Questions