use of org.kohsuke.github.GHUser in project blueocean-plugin by jenkinsci.
the class GithubScm method validateAndCreate.
@Override
public HttpResponse validateAndCreate(@JsonBody JSONObject request) {
String accessToken = (String) request.get("accessToken");
if (accessToken == null) {
throw new ServiceException.BadRequestExpception("accessToken is required");
}
try {
User authenticatedUser = getAuthenticatedUser();
HttpURLConnection connection = connect(String.format("%s/%s", getUri(), "user"), accessToken);
validateAccessTokenScopes(connection);
String data = IOUtils.toString(connection.getInputStream());
GHUser user = GithubScm.om.readValue(data, GHUser.class);
if (user.getEmail() != null) {
Mailer.UserProperty p = authenticatedUser.getProperty(Mailer.UserProperty.class);
// the one from Github?
if (p == null) {
authenticatedUser.addProperty(new Mailer.UserProperty(user.getEmail()));
}
}
//Now we know the token is valid. Lets find credential
StandardUsernamePasswordCredentials githubCredential = CredentialsUtils.findCredential(getId(), StandardUsernamePasswordCredentials.class, new BlueOceanDomainRequirement());
final StandardUsernamePasswordCredentials credential = new UsernamePasswordCredentialsImpl(CredentialsScope.USER, "github", "Github Access Token", authenticatedUser.getId(), accessToken);
if (githubCredential == null) {
CredentialsUtils.createCredentialsInUserStore(credential, authenticatedUser, getCredentialsDomainName(getUri()), ImmutableList.<DomainSpecification>of(new BlueOceanDomainSpecification()));
} else {
CredentialsUtils.updateCredentialsInUserStore(githubCredential, credential, authenticatedUser, getCredentialsDomainName(getUri()), ImmutableList.<DomainSpecification>of(new BlueOceanDomainSpecification()));
}
return createResponse(credential.getId());
} catch (IOException e) {
throw new ServiceException.UnexpectedErrorException(e.getMessage());
}
}
use of org.kohsuke.github.GHUser in project Gargoyle by callakrsos.
the class GitTest method getGargoyleRepository.
@Test
public void getGargoyleRepository() throws IOException {
GitHub github = GitHub.connect();
GHUser user = github.getUser("callakrsos");
Map<String, GHRepository> repositories = user.getRepositories();
//Repository를 모두 출력
Iterator<Entry<String, GHRepository>> iterator = repositories.entrySet().iterator();
while (iterator.hasNext()) {
Entry<String, GHRepository> next = iterator.next();
System.out.println(next.getKey() + " - " + next.getValue().getName());
}
//Gargoyle Repository 정보 출력
GHRepository repository = user.getRepository("Gargoyle");
System.out.println(repository);
List<GHContent> directoryContent = repository.getDirectoryContent("/");
//루트 디렉토리 정보 출력
directoryContent.forEach(con -> {
System.out.println(String.format("Path : %s\t\t\tsize : %d\t\t\t\tUrl:%s ", con.getPath(), con.getSize(), con.getUrl()));
});
}
use of org.kohsuke.github.GHUser in project Gargoyle by callakrsos.
the class GitTest method readContent.
@Test
public void readContent() throws IOException {
GitHub github = GitHub.connect();
GHUser user = github.getUser("callakrsos");
//Gargoyle Repository 정보 출력
GHRepository repository = user.getRepository("Gargoyle");
System.out.println(repository);
GHContent fileContent = repository.getFileContent(".project", "master");
String string = fileContent.toString();
System.out.println(string);
String downloadUrl = fileContent.getDownloadUrl();
System.out.println(downloadUrl);
String gitUrl = fileContent.getGitUrl();
System.out.println(gitUrl);
try (BufferedReader br = new BufferedReader(new InputStreamReader(fileContent.read()))) {
String readLine = null;
while ((readLine = br.readLine()) != null) {
System.out.println(readLine);
}
}
}
Aggregations