本文整理汇总了Java中org.kohsuke.github.GHCommitState类的典型用法代码示例。如果您正苦于以下问题:Java GHCommitState类的具体用法?Java GHCommitState怎么用?Java GHCommitState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GHCommitState类属于org.kohsuke.github包,在下文中一共展示了GHCommitState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onEmittedResource
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
/**
* This method is invoked when a new {@link GitRevision} has been emitted.
*
* @param holder
* @param emitter
*/
@Override
@SneakyThrows
public void onEmittedResource(ResourceHolder<GithubPullRequest> holder, ResourceEmitter<GithubPullRequest> emitter) {
try (GithubPullRequest resource = holder.acquire()) {
log.info("Received pull request " + resource.getPullRequest().getNumber());
String sha = resource.getPullRequest().getHead().getSha();
resource.getPullRequest().getRepository()
.createCommitStatus(sha,
GHCommitState.PENDING, configuration.getUrl() + "/ci/" + sha,
"Build in progress", "cicomponents");
Boolean result = new Builder(resource, outputProviderService).get();
resource.getPullRequest().getRepository()
.createCommitStatus(sha,
result ? GHCommitState.SUCCESS : GHCommitState.FAILURE,
configuration.getUrl() + "/ci/" + sha,
result ? "Success" : "Failure", "cicomponents");
}
}
示例2: execute
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
@Override
public void execute(PostJobContext context) {
GlobalReport report = new GlobalReport(markDownUtils, gitHubPluginConfiguration.tryReportIssuesInline());
try {
Map<InputFile, Map<Integer, StringBuilder>> commentsToBeAddedByLine = processIssues(report, context.issues());
updateReviewComments(commentsToBeAddedByLine);
pullRequestFacade.deleteOutdatedComments();
pullRequestFacade.createOrUpdateGlobalComments(report.hasNewIssue() ? report.formatForMarkdown() : null);
pullRequestFacade.createOrUpdateSonarQubeStatus(report.getStatus(), report.getStatusDescription());
} catch (Exception e) {
LOG.error("SonarQube analysis failed to complete the review of this pull request", e);
pullRequestFacade.createOrUpdateSonarQubeStatus(GHCommitState.ERROR, StringUtils.abbreviate("SonarQube analysis failed: " + e.getMessage(), 140));
}
}
示例3: testPullRequestAnalysisWithNewBlockerAndCriticalIssues
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
@Test
public void testPullRequestAnalysisWithNewBlockerAndCriticalIssues() throws MalformedURLException {
DefaultInputFile inputFile1 = new DefaultInputFile("foo", "src/Foo.php");
PostJobIssue newIssue = newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.CRITICAL, true, "msg1");
when(pullRequestFacade.getGithubUrl(inputFile1, 1)).thenReturn(new URL("http://github/blob/abc123/src/Foo.php#L1"));
PostJobIssue lineNotVisible = newMockedIssue("foo:src/Foo.php", inputFile1, 2, Severity.BLOCKER, true, "msg2");
when(pullRequestFacade.getGithubUrl(inputFile1, 2)).thenReturn(new URL("http://github/blob/abc123/src/Foo.php#L2"));
when(context.issues()).thenReturn(Arrays.<PostJobIssue>asList(newIssue, lineNotVisible));
when(pullRequestFacade.hasFile(inputFile1)).thenReturn(true);
when(pullRequestFacade.hasFileLine(inputFile1, 1)).thenReturn(true);
pullRequestIssuePostJob.execute(context);
verify(pullRequestFacade).createOrUpdateSonarQubeStatus(GHCommitState.ERROR, "SonarQube reported 2 issues, with 1 critical and 1 blocker");
}
示例4: updateStatus
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
void updateStatus(GHCommitState status, StageExecution stageExecution) {
ChainExecution chainExecution = stageExecution.getChainExecution();
PlanResultKey planResultKey = chainExecution.getPlanResultKey();
PlanKey planKey = planResultKey.getPlanKey();
ImmutableChain chain = (ImmutableChain) planManager.getPlanByKey(planKey);
for (RepositoryDefinition repo : Configuration.ghReposFrom(chain)) {
if (shouldUpdateRepo(chain, repo)) {
String sha = chainExecution.getBuildChanges().getVcsRevisionKey(repo.getId());
if (sha != null) {
GitHubRepository ghRepo = (GitHubRepository) repo.getRepository();
setStatus(ghRepo, status, sha, planResultKey.getKey(), stageExecution.getName());
}
}
}
}
示例5: updateStatus
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
@Override
public void updateStatus(String url, PluginSettings pluginSettings, String prIdStr, String revision, String pipelineStage,
String result, String trackbackURL) throws Exception {
String repository = getRepository(url);
GHCommitState state = getState(result);
String endPointToUse = pluginSettings.getEndPoint();
String usernameToUse = pluginSettings.getUsername();
String passwordToUse = pluginSettings.getPassword();
String oauthAccessTokenToUse = pluginSettings.getOauthToken();
if (StringUtils.isEmpty(endPointToUse)) {
endPointToUse = System.getProperty("go.plugin.build.status.github.endpoint");
}
if (StringUtils.isEmpty(usernameToUse)) {
usernameToUse = System.getProperty("go.plugin.build.status.github.username");
}
if (StringUtils.isEmpty(passwordToUse)) {
passwordToUse = System.getProperty("go.plugin.build.status.github.password");
}
if (StringUtils.isEmpty(oauthAccessTokenToUse)) {
oauthAccessTokenToUse = System.getProperty("go.plugin.build.status.github.oauth");
}
updateCommitStatus(revision, pipelineStage, trackbackURL, repository, state, usernameToUse, passwordToUse, oauthAccessTokenToUse, endPointToUse);
}
示例6: configure
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
cron = formData.getString("cron");
outputFile = formData.getString("outputFile");
unstableAs = GHCommitState.valueOf(formData.getString("unstableAs"));
autoCloseFailedPullRequests = formData.getBoolean("autoCloseFailedPullRequests");
displayBuildErrorsOnDownstreamBuilds = formData.getBoolean("displayBuildErrorsOnDownstreamBuilds");
githubAuth = req.bindJSONToList(GhprcGitHubAuth.class, formData.get("githubAuth"));
extensions = new DescribableList<GhprcExtension, GhprcExtensionDescriptor>(Saveable.NOOP);
try {
extensions.rebuildHetero(req, formData, getGlobalExtensionDescriptors(), "extensions");
} catch (IOException e) {
e.printStackTrace();
}
readBackFromLegacy();
save();
return super.configure(req, formData);
}
示例7: createCommitStatus
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
private void createCommitStatus(AbstractBuild<?, ?> build, TaskListener listener, String message, GHRepository repo, GHCommitState state) throws GhprcCommitStatusException {
GhprcCause cause = Ghprc.getCause(build);
String sha1 = cause.getCommit();
String url = Jenkins.getInstance().getRootUrl() + build.getUrl();
if (!StringUtils.isEmpty(statusUrl)) {
url = Ghprc.replaceMacros(build, listener, statusUrl);
}
String context = Util.fixEmpty(commitStatusContext);
context = Ghprc.replaceMacros(build, listener, context);
listener.getLogger().println(String.format("Setting status of %s to %s with url %s and message: '%s'", sha1, state, url, message));
if (context != null) {
listener.getLogger().println(String.format("Using context: " + context));
}
try {
repo.createCommitStatus(sha1, state, url, message, context);
} catch (IOException e) {
throw new GhprcCommitStatusException(e, state, message, cause.getPullID());
}
}
示例8: postBuildComment
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
public String postBuildComment(AbstractBuild<?, ?> build, TaskListener listener) {
StringBuilder msg = new StringBuilder();
GHCommitState state = Ghprc.getState(build);
int numLines = getLogExcerptLines();
if (state != GHCommitState.SUCCESS && numLines > 0) {
// on failure, append an excerpt of the build log
try {
// wrap log in "code" markdown
msg.append("\n\n**Build Log**\n*last ").append(numLines).append(" lines*\n");
msg.append("\n ```\n");
List<String> log = build.getLog(numLines);
for (String line : log) {
msg.append(line).append('\n');
}
msg.append("```\n");
} catch (IOException ex) {
listener.getLogger().println("Can't add log excerpt to commit comments");
ex.printStackTrace(listener.getLogger());
}
}
return msg.toString();
}
示例9: commentOnFailure
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
public void commentOnFailure(AbstractBuild<?, ?> build, TaskListener listener, GhprcCommitStatusException ex) {
PrintStream stream = null;
if (listener != null) {
stream = listener.getLogger();
}
GHCommitState state = ex.getState();
Exception baseException = ex.getException();
String newMessage;
if (baseException instanceof FileNotFoundException) {
newMessage = "FileNotFoundException means that the credentials Jenkins is using is probably wrong. Or the user account does not have write access to the repo.";
} else {
newMessage = "Could not update commit status of the Pull Request on GitHub.";
}
if (stream != null) {
stream.println(newMessage);
baseException.printStackTrace(stream);
} else {
logger.log(Level.INFO, newMessage, baseException);
}
}
示例10: testMergedMessage
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
@Test
public void testMergedMessage() throws Exception {
String mergedMessage = "Build triggered. sha1 is merged.";
given(ghprcPullRequest.getHead()).willReturn("sha");
given(ghprcPullRequest.isMergeable()).willReturn(true);
GhprcSimpleStatus status = spy(new GhprcSimpleStatus("default"));
status.onBuildTriggered(trigger, ghprcPullRequest, ghRepository);
verify(ghRepository).createCommitStatus(eq("sha"), eq(GHCommitState.PENDING), isNull(String.class), eq(mergedMessage), eq("default"));
verifyNoMoreInteractions(ghRepository);
verify(ghprcPullRequest).getHead();
verify(ghprcPullRequest).isMergeable();
verifyNoMoreInteractions(ghprcPullRequest);
}
示例11: testMergeConflictMessage
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
@Test
public void testMergeConflictMessage() throws Exception {
String mergedMessage = "Build triggered. sha1 is original commit.";
given(ghprcPullRequest.getHead()).willReturn("sha");
given(ghprcPullRequest.isMergeable()).willReturn(false);
GhprcSimpleStatus status = spy(new GhprcSimpleStatus("default"));
status.onBuildTriggered(trigger, ghprcPullRequest, ghRepository);
verify(ghRepository).createCommitStatus(eq("sha"), eq(GHCommitState.PENDING), isNull(String.class), eq(mergedMessage), eq("default"));
verifyNoMoreInteractions(ghRepository);
verify(ghprcPullRequest).getHead();
verify(ghprcPullRequest).isMergeable();
verifyNoMoreInteractions(ghprcPullRequest);
}
示例12: testDoesNotSendEmptyContext
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
@Test
public void testDoesNotSendEmptyContext() throws Exception {
String mergedMessage = "Build triggered. sha1 is original commit.";
given(ghprcPullRequest.getHead()).willReturn("sha");
given(ghprcPullRequest.isMergeable()).willReturn(false);
GhprcSimpleStatus status = spy(new GhprcSimpleStatus(""));
status.onBuildTriggered(trigger, ghprcPullRequest, ghRepository);
verify(ghRepository).createCommitStatus(eq("sha"), eq(GHCommitState.PENDING), isNull(String.class), eq(mergedMessage), isNull(String.class));
verifyNoMoreInteractions(ghRepository);
verify(ghprcPullRequest).getHead();
verify(ghprcPullRequest).isMergeable();
verifyNoMoreInteractions(ghprcPullRequest);
}
示例13: build
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
@Override
public void build(Context context) {
if (!gitHubPluginConfiguration.isEnabled()) {
return;
}
checkMode();
int pullRequestNumber = gitHubPluginConfiguration.pullRequestNumber();
pullRequestFacade.init(pullRequestNumber, context.projectReactor().getRoot().getBaseDir());
pullRequestFacade.createOrUpdateSonarQubeStatus(GHCommitState.PENDING, "SonarQube analysis in progress");
}
示例14: testPullRequestAnalysisNoIssue
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
@Test
public void testPullRequestAnalysisNoIssue() {
when(context.issues()).thenReturn(Arrays.<PostJobIssue>asList());
pullRequestIssuePostJob.execute(context);
verify(pullRequestFacade).createOrUpdateGlobalComments(null);
verify(pullRequestFacade).createOrUpdateSonarQubeStatus(GHCommitState.SUCCESS, "SonarQube reported no issues");
}
示例15: testPullRequestAnalysisWithNewIssues
import org.kohsuke.github.GHCommitState; //导入依赖的package包/类
@Test
public void testPullRequestAnalysisWithNewIssues() throws MalformedURLException {
DefaultInputFile inputFile1 = new DefaultInputFile("foo", "src/Foo.php");
PostJobIssue newIssue = newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, true, "msg1");
when(pullRequestFacade.getGithubUrl(inputFile1, 1)).thenReturn(new URL("http://github/blob/abc123/src/Foo.php#L1"));
PostJobIssue lineNotVisible = newMockedIssue("foo:src/Foo.php", inputFile1, 2, Severity.BLOCKER, true, "msg2");
when(pullRequestFacade.getGithubUrl(inputFile1, 2)).thenReturn(new URL("http://github/blob/abc123/src/Foo.php#L2"));
DefaultInputFile inputFile2 = new DefaultInputFile("foo", "src/Foo2.php");
PostJobIssue fileNotInPR = newMockedIssue("foo:src/Foo2.php", inputFile2, 1, Severity.BLOCKER, true, "msg3");
PostJobIssue notNewIssue = newMockedIssue("foo:src/Foo.php", inputFile1, 1, Severity.BLOCKER, false, "msg");
PostJobIssue issueOnDir = newMockedIssue("foo:src", Severity.BLOCKER, true, "msg4");
PostJobIssue issueOnProject = newMockedIssue("foo", Severity.BLOCKER, true, "msg");
PostJobIssue globalIssue = newMockedIssue("foo:src/Foo.php", inputFile1, null, Severity.BLOCKER, true, "msg5");
when(context.issues()).thenReturn(Arrays.<PostJobIssue>asList(newIssue, globalIssue, issueOnProject, issueOnDir, fileNotInPR, lineNotVisible, notNewIssue));
when(pullRequestFacade.hasFile(inputFile1)).thenReturn(true);
when(pullRequestFacade.hasFileLine(inputFile1, 1)).thenReturn(true);
pullRequestIssuePostJob.execute(context);
verify(pullRequestFacade).createOrUpdateGlobalComments(contains("SonarQube analysis reported 5 issues"));
verify(pullRequestFacade)
.createOrUpdateGlobalComments(contains("* ![BLOCKER][BLOCKER] 5 blocker"));
verify(pullRequestFacade)
.createOrUpdateGlobalComments(
not(contains("1. [Project")));
verify(pullRequestFacade)
.createOrUpdateGlobalComments(
contains(
"1. ![BLOCKER][BLOCKER] [Foo.php#L2](http://github/blob/abc123/src/Foo.php#L2): msg2 [![rule](https://sonarsource.github.io/sonar-github/rule.png)](http://myserver/coding_rules#rule_key=repo%3Arule)"));
verify(pullRequestFacade).createOrUpdateSonarQubeStatus(GHCommitState.ERROR, "SonarQube reported 5 issues, with 5 blocker");
}