use of org.kohsuke.stapler.verb.GET in project blueocean-plugin by jenkinsci.
the class GithubScm method getRepository.
/**
* @param jobName the job name
* @param apiUrl github api url
* @return GHRepository used by the job
*/
@GET
@WebMethod(name = "repository")
@TreeResponse
public GithubRepository getRepository(@QueryParameter String jobName, @QueryParameter String apiUrl) {
Item item = Jenkins.get().getItem(jobName);
if (item == null) {
throw new ServiceException.NotFoundException(String.format("Job %s not found", jobName));
}
GitHubSCMSource gitHubSCMSource = ((GitHubSCMSource) ((WorkflowMultiBranchProject) item).getSCMSource("blueocean"));
if (gitHubSCMSource == null) {
throw new ServiceException.NotFoundException(String.format("GitHubSCMSource for Job %s not found", jobName));
}
String repoOwner = gitHubSCMSource.getRepoOwner();
String repoName = gitHubSCMSource.getRepository();
StandardUsernamePasswordCredentials credential = getCredential();
String accessToken = credential.getPassword().getPlainText();
try {
String url = String.format("%s/repos/%s/%s", apiUrl, repoOwner, repoName);
GHRepository ghRepository = HttpRequest.get(url).withAuthorizationToken(accessToken).to(GHRepository.class);
return new GithubRepository(ghRepository, credential, this);
} catch (IOException e) {
throw new ServiceException.UnexpectedErrorException(e.getMessage(), e);
}
}
use of org.kohsuke.stapler.verb.GET in project blueocean-plugin by jenkinsci.
the class PipelineMetadataService method doAgentMetadata.
/**
* Function to return all {@link DeclarativeAgent}s present in the system when accessed through the REST API
*/
@GET
@TreeResponse
public ExportedDescribableModel[] doAgentMetadata() {
List<ExportedDescribableModel> models = new ArrayList<>();
for (DeclarativeAgentDescriptor d : DeclarativeAgentDescriptor.all()) {
try {
DescribableModel<? extends DeclarativeAgent> model = new DescribableModel<>(d.clazz);
String symbol = symbolForObject(d);
if ("label".equals(symbol)) {
// Label has 2 symbols, but we need "node"
symbol = "node";
}
models.add(new ExportedDescribableModel(model, symbol));
} catch (NoStaplerConstructorException e) {
// Ignore!
}
}
return models.toArray(new ExportedDescribableModel[0]);
}
use of org.kohsuke.stapler.verb.GET in project blueocean-plugin by jenkinsci.
the class PipelineMetadataService method doBuildConditions.
/**
* Function to return the names of all build conditions present in the system when accessed through the REST API
*/
@GET
@TreeResponse
public ExportedBuildCondition[] doBuildConditions() {
List<ExportedBuildCondition> exported = new ArrayList<>();
for (BuildCondition c : BuildCondition.all()) {
exported.add(new ExportedBuildCondition(symbolForObject(c), c.getDescription()));
}
Collections.sort(exported, new Comparator<ExportedBuildCondition>() {
@Override
public int compare(ExportedBuildCondition o1, ExportedBuildCondition o2) {
return o1.getName().compareTo(o2.getName());
}
});
return exported.toArray(new ExportedBuildCondition[exported.size()]);
}
use of org.kohsuke.stapler.verb.GET in project blueocean-plugin by jenkinsci.
the class PipelineMetadataService method doPipelineStepMetadata.
/**
* Function to return all step descriptors present in the system when accessed through the REST API
*/
@GET
@TreeResponse
public ExportedPipelineFunction[] doPipelineStepMetadata() {
List<ExportedPipelineFunction> pd = new ArrayList<>();
for (StepDescriptor d : StepDescriptor.all()) {
if (includeStep(d)) {
ExportedPipelineStep step = getStepMetadata(d);
if (step != null) {
pd.add(step);
}
}
}
List<Descriptor<?>> metaStepDescriptors = new ArrayList<Descriptor<?>>();
populateMetaSteps(metaStepDescriptors, Builder.class);
populateMetaSteps(metaStepDescriptors, Publisher.class);
populateMetaSteps(metaStepDescriptors, BuildWrapper.class);
for (Descriptor<?> d : metaStepDescriptors) {
ExportedPipelineFunction metaStep = getStepMetadata(d);
if (metaStep != null) {
pd.add(metaStep);
}
}
return pd.toArray(new ExportedPipelineFunction[pd.size()]);
}
use of org.kohsuke.stapler.verb.GET in project blueocean-plugin by jenkinsci.
the class PipelineMetadataService method doToolMetadata.
/**
* Function to return all {@link ExportedToolDescriptor}s present in the system when accessed through the REST API,
* pipeline scripts need: symbol and name to specify tools
*/
@GET
@TreeResponse
public ExportedToolDescriptor[] doToolMetadata() {
List<ExportedToolDescriptor> models = new ArrayList<>();
for (ToolDescriptor<? extends ToolInstallation> d : ToolInstallation.all()) {
ExportedToolDescriptor descriptor = new ExportedToolDescriptor(d.getDisplayName(), symbolForObject(d), d.getClass());
models.add(descriptor);
for (ToolInstallation installation : d.getInstallations()) {
descriptor.addInstallation(new ExportedToolDescriptor.ExportedToolInstallation(installation.getName(), installation.getClass()));
}
}
return models.toArray(new ExportedToolDescriptor[0]);
}
Aggregations