org.gitlab4j.api.Constants Java Examples
The following examples show how to use
org.gitlab4j.api.Constants.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileUtils.java From choerodon-starters with Apache License 2.0 | 5 votes |
/** * Reads the content of a File instance and returns it as a String of either text or base64 encoded text. * * @param file the File instance to read from * @param encoding whether to encode as Base64 or as Text, defaults to Text if null * @return the content of the File as a String * @throws IOException if any error occurs */ public static String getFileContentAsString(File file, Constants.Encoding encoding) throws IOException { if (encoding == Constants.Encoding.BASE64) { try (FileInputStream stream = new FileInputStream(file)) { byte data[] = new byte[(int) file.length()]; stream.read(data); return (Base64.getEncoder().encodeToString(data)); } } else { return (new String(Files.readAllBytes(file.toPath()))); } }
Example #2
Source File: GitLabPipelineStatusNotifier.java From gitlab-branch-source-plugin with MIT License | 4 votes |
/** * Sends notifications to GitLab on Checkout (for the "In Progress" Status). */ private static void sendNotifications(Run<?, ?> build, TaskListener listener) { GitLabSCMSource source = getSource(build); if (source == null) { return; } final GitLabSCMSourceContext sourceContext = getSourceContext(build, source); if (sourceContext.notificationsDisabled()) { return; } String url = getRootUrl(build); if (url.isEmpty()) { listener.getLogger().println( "Can not determine Jenkins root URL. Commit status notifications are disabled until a root URL is" + " configured in Jenkins global configuration."); return; } Result result = build.getResult(); LOGGER.log(Level.FINE, String.format("Result: %s", result)); CommitStatus status = new CommitStatus(); Constants.CommitBuildState state; status.setTargetUrl(url); if (Result.SUCCESS.equals(result)) { status.setDescription(build.getParent().getFullName() + ": This commit looks good"); status.setStatus("SUCCESS"); state = Constants.CommitBuildState.SUCCESS; } else if (Result.UNSTABLE.equals(result)) { status.setDescription( build.getParent().getFullName() + ": This commit has test failures"); status.setStatus("FAILED"); state = Constants.CommitBuildState.FAILED; } else if (Result.FAILURE.equals(result)) { status.setDescription( build.getParent().getFullName() + ": There was a failure building this commit"); status.setStatus("FAILED"); state = Constants.CommitBuildState.FAILED; } else if (result != null) { // ABORTED, NOT_BUILT. status.setDescription(build.getParent().getFullName() + ": Something is wrong with the build of this commit"); status.setStatus("CANCELED"); state = Constants.CommitBuildState.CANCELED; } else { status.setDescription(build.getParent().getFullName() + ": Build started..."); status.setStatus("RUNNING"); state = Constants.CommitBuildState.RUNNING; } final SCMRevision revision = SCMRevisionAction.getRevision(source, build); String hash; if (revision instanceof BranchSCMRevision) { listener.getLogger() .format("[GitLab Pipeline Status] Notifying branch build status: %s %s%n", status.getStatus(), status.getDescription()); hash = ((BranchSCMRevision) revision).getHash(); } else if (revision instanceof MergeRequestSCMRevision) { listener.getLogger() .format("[GitLab Pipeline Status] Notifying merge request build status: %s %s%n", status.getStatus(), status.getDescription()); hash = ((MergeRequestSCMRevision) revision).getOrigin().getHash(); } else if (revision instanceof GitTagSCMRevision) { listener.getLogger() .format("[GitLab Pipeline Status] Notifying tag build status: %s %s%n", status.getStatus(), status.getDescription()); hash = ((GitTagSCMRevision) revision).getHash(); } else { return; } status.setName(getStatusName(sourceContext, build, revision)); final JobScheduledListener jsl = ExtensionList.lookup(QueueListener.class) .get(JobScheduledListener.class); if (jsl != null) { // we are setting the status, so don't let the queue listener background thread change it to pending synchronized (jsl.resolving) { jsl.resolving.remove(build.getParent()); } } try { GitLabApi gitLabApi = GitLabHelper.apiBuilder(source.getServerName()); LOGGER.log(Level.FINE, String.format("Notifiying commit: %s", hash)); gitLabApi.getCommitsApi().addCommitStatus( source.getProjectPath(), hash, state, status); listener.getLogger().format("[GitLab Pipeline Status] Notified%n"); } catch (GitLabApiException e) { if(!e.getMessage().contains(("Cannot transition status"))) { LOGGER.log(Level.WARNING, String.format("Exception caught: %s",e.getMessage())); } } }
Example #3
Source File: MergeRequestFilter.java From gitlab4j-api with MIT License | 4 votes |
@JsonIgnore public GitLabApiForm getQueryParams(int page, int perPage) { return (getQueryParams() .withParam(Constants.PAGE_PARAM, page) .withParam(Constants.PER_PAGE_PARAM, perPage)); }
Example #4
Source File: DeployToken.java From gitlab4j-api with MIT License | 4 votes |
public List<Constants.DeployTokenScope> getScopes() { return scopes; }
Example #5
Source File: DeployToken.java From gitlab4j-api with MIT License | 4 votes |
public void setScopes(List<Constants.DeployTokenScope> scopes) { this.scopes = scopes; }
Example #6
Source File: IssueFilter.java From gitlab4j-api with MIT License | 4 votes |
@JsonIgnore public GitLabApiForm getQueryParams(int page, int perPage) { return (getQueryParams() .withParam(Constants.PAGE_PARAM, page) .withParam(Constants.PER_PAGE_PARAM, perPage)); }
Example #7
Source File: CommitStatusFilter.java From gitlab4j-api with MIT License | 4 votes |
@JsonIgnore public GitLabApiForm getQueryParams(int page, int perPage) { return (getQueryParams() .withParam(Constants.PAGE_PARAM, page) .withParam(Constants.PER_PAGE_PARAM, perPage)); }
Example #8
Source File: ProjectFilter.java From gitlab4j-api with MIT License | 2 votes |
/** * Get the query params specified by this filter. * * @param page specifies the page number * @param perPage specifies the number of items per page * @return a GitLabApiForm instance holding the query parameters for this ProjectFilter instance */ public GitLabApiForm getQueryParams(int page, int perPage) { return (getQueryParams() .withParam(Constants.PAGE_PARAM, page) .withParam(Constants.PER_PAGE_PARAM, perPage)); }