public void run() throws Exception {
   GitHub gh = GitHub.connect();
   GHOrganization org = gh.getOrganization("jenkinsci");
   for (GHRepository r : org.listRepositories()) {
     // as a roll out, only do this for 60% of the repositories
     if (r.getName().hashCode() % 10 < 6 && !r.getName().equals("jenkins")) greet(r);
   }
 }
예제 #2
0
	public DynamicProject createNewProject(GHRepository githubRepository) {
		try {
			new GithubRepositoryService(githubRepository).linkProjectToCi();

			OrganizationContainer folder = this.organizationRepository.getOrCreateContainer(githubRepository.getOwner().getLogin());
			String projectName = githubRepository.getName();
			DynamicProject project = folder.createProject(DynamicProject.class, projectName);

			project.setDescription(format("<a href=\"%s\">%s</a>", githubRepository.getUrl(), githubRepository.getUrl()));
			project.setConcurrentBuild(true);
			if (StringUtils.isNotEmpty(SetupConfig.get().getLabel())) {
				project.setAssignedLabel(Jenkins.getInstance().getLabel(SetupConfig.get().getLabel()));
			}
			project.addProperty(new ParametersDefinitionProperty(new StringParameterDefinition("BRANCH", "master")));
			project.addProperty(new GithubRepoProperty(githubRepository.getUrl()));

			project.getPublishersList().add(new DotCiNotifier());
			project.save();
			folder.addItem(project);
			folder.save();
			return project;
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
 private GHRepository mockGHRepository(String ownerName, String name) throws IOException {
   GHRepository ghRepository = PowerMockito.mock(GHRepository.class);
   GHUser ghUser = PowerMockito.mock(GHUser.class);
   PowerMockito.when(ghUser.getLogin()).thenReturn(ownerName);
   PowerMockito.when(ghRepository.getOwner()).thenReturn(ghUser);
   PowerMockito.when(ghRepository.getName()).thenReturn(name);
   return ghRepository;
 }
예제 #4
0
 /**
  * Creates a repository local team, and grants access to the repository.
  */
 private GHTeam getOrCreateRepoLocalTeam(GHOrganization org, GHRepository r) throws IOException {
     String teamName = r.getName() + " Developers";
     GHTeam t = org.getTeams().get(teamName);
     if (t==null) {
         t = org.createTeam(teamName, Permission.ADMIN, r);
     } else {
         t.add(r);
     }
     return t;
 }
예제 #5
0
 /** Creates a new team and assigns the repositories. */
 public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories)
     throws IOException {
   Requester post = new Requester(root).with("name", name).with("permission", p);
   List<String> repo_names = new ArrayList<String>();
   for (GHRepository r : repositories) {
     repo_names.add(r.getName());
   }
   post.with("repo_names", repo_names);
   return post.method("POST").to("/orgs/" + login + "/teams", GHTeam.class).wrapUp(this);
 }
 private Set<GhprbRepository> getRepos(GHRepository repo) throws IOException {
   try {
     return getRepos(repo.getOwner().getLogin() + "/" + repo.getName());
   } catch (Exception ex) {
     logger.log(Level.WARNING, "Can't get a valid owner for repo");
     // this normally happens due to missing "login" field in the owner of the repo
     // when the repo is inside of an organisation account. The only field which doesn't
     // rely on the owner.login (which would throw a null pointer exception) is the "html_url"
     // field. So we try to parse the owner out of that here until github fixes his api
     String repoUrl = repo.getUrl();
     if (repoUrl.endsWith("/")) { // strip off trailing slash if any
       repoUrl = repoUrl.substring(0, repoUrl.length() - 2);
     }
     int slashIndex = repoUrl.lastIndexOf('/');
     String owner = repoUrl.substring(slashIndex + 1);
     logger.log(Level.INFO, "Parsed {0} from {1}", new Object[] {owner, repoUrl});
     return getRepos(owner + "/" + repo.getName());
   }
 }
예제 #7
0
 /** Creates a new team and assigns the repositories. */
 public GHTeam createTeam(String name, Permission p, Collection<GHRepository> repositories)
     throws IOException {
   Poster post =
       new Poster(root)
           .withCredential()
           .with("team[name]", name)
           .with("team[permission]", p.name().toLowerCase());
   for (GHRepository r : repositories) {
     post.with("team[repo_names][]", r.getOwnerName() + '/' + r.getName());
   }
   return post.to("/organizations/" + login + "/teams", JsonTeam.class).wrap(this);
 }
 /** Does this repository match the repository referenced in the given {@link GHCommitPointer}? */
 public boolean matches(GHRepository repo) throws IOException {
   return userName.equals(repo.getOwner().getLogin()) // TODO: use getOwnerName
       && repositoryName.equals(repo.getName())
       && host.equals(new URL(repo.getUrl()).getHost());
 }
예제 #9
0
	public boolean projectExists(GHRepository repository) throws IOException {
		OrganizationContainer folder = this.organizationRepository.getOrganizationContainer(repository.getOwner().getLogin());
		return folder != null && folder.getItem(repository.getName()) != null;
	}