Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable issue reporter configs. #1

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/codety.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ jobs:
# CODETY_TOKEN: ${{ secrets.CODETY_TOKEN_PROD }}
#test:
CODETY_TOKEN: ${{ secrets.CODETY_TOKEN_TEST }}
CODETY_HOST: ${{ vars.CODETY_HOST_TEST }}
# CODETY_HOST: ${{ vars.CODETY_HOST_TEST }}

CODETY_ENABLE_SLACK_NOTIFICATION: true
CODETY_ISSUE_REPORTER_SLACK: true
SLACK_OAUTH_TOKEN: ${{ secrets.SLACK_OAUTH_TOKEN_TEST_INTEGRATION }}
SLACK_CONVERSATION_ID: ${{ vars.SLACK_CONVERSATION_ID }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public class AnalyzerRequest {
private boolean enablePostingPullRequestComment = true;
private boolean enablePostingPullRequestReviews = true;
private boolean enablePostingGitHubPullRequestCheckRunAnnotations = true;
private boolean enableConsoleIssueReporter = true;

private GitProviderType gitProviderType;
private ComputeRunnerType computeRunnerType;


private String localGitRepoPath;
private String gitRepoFullName;
private String externalGitRepoOwnerId;
Expand Down Expand Up @@ -84,12 +86,19 @@ public static AnalyzerRequest processSystemVariablesToRequest(Map<String, String
analyzerRequest.setCodetyToken(envMap.get(CodetyConstant.ENV_CODETY_TOKEN));
analyzerRequest.setCodetyHost(envMap.get(CodetyConstant.ENV_CODETY_HOST));

analyzerRequest.enableSlackNotification = "true".equals(envMap.get(CodetyConstant.ENV_CODETY_ENABLE_SLACK_NOTIFICATION));
analyzerRequest.enableSlackNotification = "true".equals(envMap.get(CodetyConstant.ENV_CODETY_ISSUE_REPORTER_SLACK));
if(analyzerRequest.enableSlackNotification) {
analyzerRequest.slackOauthToken = (envMap.get(CodetyConstant.ENV_SLACK_OAUTH_TOKEN));
analyzerRequest.slackConversationId = (envMap.get(CodetyConstant.ENV_SLACK_CONVERSATION_ID));
}

analyzerRequest.enableConsoleIssueReporter = !"false".equals(envMap.get(CodetyConstant.ENV_CODETY_ISSUE_REPORTER_CONSOLE));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codety
CodetyBot:

  • 🔴 [Error Prone] [AvoidDuplicateLiterals] The String literal 'false' appears 4 times in this file; the first occurrence is on line 95

analyzerRequest.enablePostingPullRequestComment = !"false".equals(envMap.get(CodetyConstant.ENV_CODETY_ISSUE_REPORTER_GITHUB_PR_COMMENT));
analyzerRequest.enablePostingPullRequestReviews = !"false".equals(envMap.get(CodetyConstant.ENV_CODETY_ISSUE_REPORTER_GITHUB_PR_REVIEW));
analyzerRequest.enablePostingGitHubPullRequestCheckRunAnnotations = !"false".equals(envMap.get(CodetyConstant.ENV_CODETY_ISSUE_REPORTER_GITHUB_PR_CHECK_RUN_ANNOTATION));



String handleDiff = envMap.get(CodetyConstant.ENV_CODETY_REPORT_ALL_ISSUES);
if(handleDiff == null || "0".equals(handleDiff)){
analyzerRequest.setFilterByGitDiff(true);
Expand Down Expand Up @@ -423,4 +432,12 @@ public void setSlackOauthToken(String slackOauthToken) {
public void setSlackConversationId(String slackConversationId) {
this.slackConversationId = slackConversationId;
}

public boolean isEnableConsoleIssueReporter() {
return enableConsoleIssueReporter;
}

public void setEnableConsoleIssueReporter(boolean enableConsoleIssueReporter) {
this.enableConsoleIssueReporter = enableConsoleIssueReporter;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codety
CodetyBot:

  • 🔴 [security] [vault-token] Detected potential exposure of sensitive information

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ public class CodetyConstant {
public static final String ENV_CODETY_TOKEN = "CODETY_TOKEN";
public static final String ENV_SLACK_OAUTH_TOKEN = "SLACK_OAUTH_TOKEN";
public static final String ENV_SLACK_CONVERSATION_ID = "SLACK_CONVERSATION_ID";
public static final String ENV_CODETY_ENABLE_SLACK_NOTIFICATION = "CODETY_ENABLE_SLACK_NOTIFICATION";
public static final String ENV_CODETY_ISSUE_REPORTER_SLACK = "CODETY_ISSUE_REPORTER_SLACK";
public static final String ENV_CODETY_ISSUE_REPORTER_CONSOLE = "CODETY_ISSUE_REPORTER_CONSOLE";
public static final String ENV_CODETY_ISSUE_REPORTER_GITHUB_PR_COMMENT = "CODETY_ISSUE_REPORTER_GITHUB_PR_COMMENT";
public static final String ENV_CODETY_ISSUE_REPORTER_GITHUB_PR_REVIEW = "CODETY_ISSUE_REPORTER_GITHUB_PR_REVIEW";
public static final String ENV_CODETY_ISSUE_REPORTER_GITHUB_PR_CHECK_RUN_ANNOTATION = "CODETY_ISSUE_REPORTER_GITHUB_PR_CHECK_RUN_ANNOTATION";
public static final String ENV_CODETY_HOST = "CODETY_HOST";
public static final String ENV_CODETY_REPORT_ALL_ISSUES = "CODETY_REPORT_ALL_ISSUES";
public static final String ENV_CODETY_CONNECTION_TIMEOUT = "CODETY_TIMEOUT";


public static final String COMMAND_GIT = "git";
public static final String[] COMMAND_GIT_FETCH = new String[]{COMMAND_GIT, "fetch"};
public static final String INFO_PR_COMMENT_POSTED = "Posted the code analysis result to ";
Expand Down
32 changes: 31 additions & 1 deletion scanner/doc/predefined-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,46 @@ For troubleshooting purposes only.

#### CODETY_REPORT_ALL_ISSUES
type: boolean

value: false | true

#### CODETY_PRINT_TO_CONSOLE
#### CODETY_ISSUE_REPORTER_CONSOLE
type: boolean

value: false | true, default: true

#### CODETY_ISSUE_REPORTER_GITHUB_PR_COMMENT
default: true

type: boolean

value: false | true, default: true

#### CODETY_ISSUE_REPORTER_GITHUB_PR_REVIEW
default: true

type: boolean

value: false | true, default: true

#### CODETY_ISSUE_REPORTER_GITHUB_PR_CHECK_RUN_ANNOTATION
type: boolean

value: false | true, default: true

#### GITHUB_TOKEN
The token will be used for posting pull request review comments
Below GitHub permissions are needed within the Codety Scanner runtime scope:
* `pull-requests: write`
* `contents: read`

#### CODETY_ISSUE_REPORTER_SLACK
type: boolean

value: false | true, default: false



#### SLACK_OAUTH_TOKEN
The token will be used for Slack notification integration.
Below Slack permissions are needed:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ public boolean distributeAnalysisResult(AnalyzerRequest analyzerRequest, CodeAna
}



consoleResultReporter.deliverResult(analyzerRequest, codeAnalysisResultSetDto);

githubPullRequestResultReporter.deliverResult(analyzerRequest, codeAnalysisResultSetDto);

slackResultReporter.deliverResult(analyzerRequest, codeAnalysisResultSetDto);

sarifResultReporter.deliverResult(analyzerRequest, codeAnalysisResultSetDto);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public class ConsoleResultReporter implements ResultReporter {
@Override
public void deliverResult(AnalyzerRequest analyzerRequest, CodeAnalysisResultSetDto codeAnalysisResultSetDto) {

if(!analyzerRequest.isEnableConsoleIssueReporter()) {
CodetyConsoleLogger.info("Skip posting issue result into console terminal");
}

String consoleOutputString = codeAnalysisResultSetDto.toConsoleOutputString(analyzerRequest);
if(consoleOutputString!=null && consoleOutputString.length() > 0) {
CodetyConsoleLogger.info(CodetyConstant.INFO_SHOW_ANALYSIS_RESULT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public void deliverResult(AnalyzerRequest analyzerRequest, CodeAnalysisResultSet
StringBuilder pullRequestComment = createPullRequestComment(analyzerRequest, codeAnalysisResultDtoList);
githubCommentService.addOrUpdatePullRequestComment(analyzerRequest, pullRequestComment.toString());
}
// if(analyzerRequest.isEnablePostingGitHubPullRequestCheckRunAnnotations()){
// githubCommentService.addCheckRunAnnotations(analyzerRequest, codeAnalysisResultDtoList);
// }
if(analyzerRequest.isEnablePostingGitHubPullRequestCheckRunAnnotations()){
githubCommentService.addCheckRunAnnotations(analyzerRequest, codeAnalysisResultDtoList);
}
}

}
Expand Down