use of jenkins.scm.api.SCMNavigator in project blueocean-plugin by jenkinsci.
the class GithubScmContentProvider method saveContent.
@SuppressWarnings("unchecked")
private Object saveContent(@Nonnull GithubScmSaveFileRequest githubRequest, @Nonnull Item item) {
String apiUrl = GithubScm.DEFAULT_API_URI;
String owner = null;
String repo = null;
String accessToken = null;
String credentialId = null;
if (item instanceof OrganizationFolder) {
List<SCMNavigator> navigators = ((OrganizationFolder) item).getSCMNavigators();
if (!navigators.isEmpty() && navigators.get(0) instanceof GitHubSCMNavigator) {
GitHubSCMNavigator navigator = (GitHubSCMNavigator) navigators.get(0);
if (navigator.getApiUri() != null) {
apiUrl = navigator.getApiUri();
}
credentialId = navigator.getScanCredentialsId();
owner = navigator.getRepoOwner();
}
} else if (item instanceof MultiBranchProject) {
List<SCMSource> sources = ((MultiBranchProject) item).getSCMSources();
if (!sources.isEmpty() && sources.get(0) instanceof GitHubSCMSource) {
GitHubSCMSource source = (GitHubSCMSource) sources.get(0);
if (source.getApiUri() != null) {
apiUrl = source.getApiUri();
}
credentialId = source.getScanCredentialsId();
owner = owner(source);
repo = repo(source);
}
}
if (credentialId != null) {
StandardCredentials credentials = Connector.lookupScanCredentials((SCMSourceOwner) item, apiUrl, credentialId);
if (credentials instanceof StandardUsernamePasswordCredentials) {
accessToken = ((StandardUsernamePasswordCredentials) credentials).getPassword().getPlainText();
} else {
throw new ServiceException.BadRequestExpception("accessToken not found in pipeline: " + item.getFullName());
}
}
return githubRequest.save(apiUrl, owner, repo, accessToken);
}
use of jenkins.scm.api.SCMNavigator in project blueocean-plugin by jenkinsci.
the class GithubPipelineUpdateRequest method getNavigator.
@SuppressWarnings("unchecked")
private GitHubSCMNavigator getNavigator(OrganizationFolder folder) throws IOException {
String apiUrl = null;
String credentialId = null;
String orgName = null;
StringBuilder sb = new StringBuilder();
if (scmConfig != null) {
apiUrl = scmConfig.getUri();
credentialId = scmConfig.getCredentialId();
if (scmConfig.getConfig().get("orgName") instanceof String) {
orgName = (String) scmConfig.getConfig().get("orgName");
}
}
for (SCMNavigator navigator : folder.getNavigators()) {
if (navigator instanceof GitHubSCMNavigator) {
GitHubSCMNavigator scmNavigator = (GitHubSCMNavigator) navigator;
if (scmNavigator.getApiUri() != null && !scmNavigator.getApiUri().equals(apiUrl)) {
apiUrl = scmNavigator.getApiUri();
}
if (scmNavigator.getScanCredentialsId() != null && !scmNavigator.getScanCredentialsId().equals(credentialId)) {
credentialId = scmNavigator.getScanCredentialsId();
}
if (!scmNavigator.getRepoOwner().equals(orgName)) {
orgName = scmNavigator.getRepoOwner();
}
GitHubSCMNavigator gitHubSCMNavigator = new GitHubSCMNavigator(apiUrl, orgName, credentialId, credentialId);
GithubPipelineCreateRequest.validateCredentialId(credentialId, apiUrl);
if (scmConfig != null && scmConfig.getConfig().get("repos") instanceof List) {
for (String r : (List<String>) scmConfig.getConfig().get("repos")) {
sb.append(String.format("(%s\\b)?", r));
repos.add(r);
}
}
if (sb.length() > 0) {
gitHubSCMNavigator.setPattern(sb.toString());
}
return gitHubSCMNavigator;
}
}
return null;
}
Aggregations