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

feat: add support to pass analyzer type using --analyzer-type flag #227

Merged
merged 3 commits into from
Nov 9, 2023
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ cover.out

# Completion files
completions

.vscode
5 changes: 4 additions & 1 deletion command/report/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package report

const (
cliVersion = "v0.1.6"
CliVersion = "v0.8.0"
commonUsageMessage = `
Usage:
deepsource <command> [<arguments>]
Expand All @@ -18,14 +18,17 @@ Usage:
deepsource report [<arguments>]
Available arguments are:
--analyzer Shortcode of the analyzer
--analyzer-type Type of the analyzer (default: "core")
--key Name of the artifact
--value Value of the artifact
--value-file Path to the artifact value file
Examples:
deepsource report --analyzer test-coverage --key python --value-file ./coverage.xml
deepsource report --analyzer git --key lines-changed --value 22
deepsource report --analyzer kube-linter --type community --value-file ./kube-linter.sarif
Notes:
- Pass either '--value' or '--value-file'. If both are passed, contents of '--value' will be considered.
- '--analyzer-type' is optional. If not passed, it will default to 'core'.
Documentation:
https://deepsource.io/docs/cli#report
`
Expand Down
17 changes: 15 additions & 2 deletions command/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

type ReportOptions struct {
Analyzer string
AnalyzerType string
Key string
Value string
ValueFile string
Expand Down Expand Up @@ -57,6 +58,8 @@ func NewCmdReport() *cobra.Command {
// --repo, -r flag
cmd.Flags().StringVar(&opts.Analyzer, "analyzer", "", "name of the analyzer to report the artifact to (example: test-coverage)")

cmd.Flags().StringVar(&opts.AnalyzerType, "analyzer-type", "", "type of the analyzer (example: community)")

cmd.Flags().StringVar(&opts.Key, "key", "", "shortcode of the language (example: go)")

cmd.Flags().StringVar(&opts.Value, "value", "", "value of the artifact")
Expand Down Expand Up @@ -85,6 +88,7 @@ func (opts *ReportOptions) Run() int {
/////////////////////

reportCommandAnalyzerShortcode := strings.TrimSpace(opts.Analyzer)
reportCommandAnalyzerType := strings.TrimSpace(opts.AnalyzerType)
reportCommandKey := strings.TrimSpace(opts.Key)
reportCommandValue := opts.Value
reportCommandValueFile := strings.TrimSpace(opts.ValueFile)
Expand Down Expand Up @@ -198,10 +202,12 @@ func (opts *ReportOptions) Run() int {
}

var analyzerShortcode string
var analyzerType string
var artifactKey string
var artifactValue string

analyzerShortcode = reportCommandAnalyzerShortcode
analyzerType = reportCommandAnalyzerType
artifactKey = reportCommandKey

if reportCommandValue != "" {
Expand Down Expand Up @@ -299,14 +305,21 @@ func (opts *ReportOptions) Run() int {
AccessToken: dsnAccessToken,
CommitOID: headCommitOID,
ReporterName: "cli",
ReporterVersion: cliVersion,
ReporterVersion: CliVersion,
Key: artifactKey,
Data: artifactValue,
AnalyzerShortcode: analyzerShortcode,
Metadata: reportMeta,
// AnalyzerType: analyzerType, // Add this in the later steps, only is the analyzer type is passed.
// This makes sure that the cli is always backwards compatible. The API is designed to accept analyzer type only if it is passed.
Metadata: reportMeta,
}

query := ReportQuery{Query: reportGraphqlQuery}
// Check if analyzerType is passed and add it to the queryInput
if analyzerType != "" {
queryInput.AnalyzerType = analyzerType
}
// Pass queryInput to the query
query.Variables.Input = queryInput

// Marshal request body
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"query": "mutation($input: CreateArtifactInput!) {\r\n createArtifact(input: $input) {\r\n ok\r\n message\r\n error\r\n }\r\n}",
"variables": {
"input": {
"accessToken": "f59ab9314307",
"commitOid": "b9e678d8dcb43fa1340e8a0c579b2c642280dc27",
"reporter": "cli",
"reporterVersion": "v0.1.6",
"key": "python",
"data": "\u003c?xml version=\"1.0\" ?\u003e\n\u003ccoverage branch-rate=\"0.9333\" branches-covered=\"28\" branches-valid=\"30\" complexity=\"0\" line-rate=\"0.9839\" lines-covered=\"183\" lines-valid=\"186\" timestamp=\"1551180635459\" version=\"4.5.2\"\u003e\n \u003c!-- Generated by coverage.py: https://coverage.readthedocs.io --\u003e\n \u003c!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd --\u003e\n \u003csources/\u003e\n \u003cpackages\u003e\n \u003cpackage branch-rate=\"0.9333\" complexity=\"0\" line-rate=\"0.9839\" name=\".Users.sanket.Code.s3tree.s3tree\"\u003e\n \u003cclasses\u003e\n \u003cclass branch-rate=\"1\" complexity=\"0\" filename=\"/code/s3tree/s3tree/__init__.py\" line-rate=\"1\" name=\"__init__.py\"\u003e\n \u003cmethods/\u003e\n \u003clines\u003e\n \u003cline hits=\"1\" number=\"4\"/\u003e\n \u003cline hits=\"1\" number=\"6\"/\u003e\n \u003cline hits=\"1\" number=\"7\"/\u003e\n \u003cline hits=\"1\" number=\"9\"/\u003e\n \u003cline hits=\"1\" number=\"10\"/\u003e\n \u003cline hits=\"1\" number=\"12\"/\u003e\n \u003c/lines\u003e\n \u003c/class\u003e\n \u003cclass branch-rate=\"1\" complexity=\"0\" filename=\"/code/s3tree/s3tree/__version__.py\" line-rate=\"1\" name=\"__version__.py\"\u003e\n \u003cmethods/\u003e\n \u003clines\u003e\n \u003cline hits=\"1\" number=\"4\"/\u003e\n \u003c/lines\u003e\n \u003c/class\u003e\n \u003cclass branch-rate=\"0.9375\" complexity=\"0\" filename=\"/code/s3tree/s3tree/core.py\" line-rate=\"0.9846\" name=\"core.py\"\u003e\n \u003cmethods/\u003e\n \u003clines\u003e\n \u003cline hits=\"1\" number=\"4\"/\u003e\n \u003cline hits=\"1\" number=\"5\"/\u003e\n \u003cline hits=\"1\" number=\"6\"/\u003e\n \u003cline hits=\"1\" number=\"7\"/\u003e\n \u003cline hits=\"1\" number=\"8\"/\u003e\n \u003cline hits=\"1\" number=\"10\"/\u003e\n \u003cline hits=\"1\" number=\"11\"/\u003e\n \u003cline hits=\"1\" number=\"13\"/\u003e\n \u003cline hits=\"1\" number=\"14\"/\u003e\n \u003cline hits=\"1\" number=\"17\"/\u003e\n \u003cline hits=\"1\" number=\"41\"/\u003e\n \u003cline hits=\"1\" number=\"43\"/\u003e\n \u003cline hits=\"1\" number=\"45\"/\u003e\n \u003cline hits=\"1\" number=\"49\"/\u003e\n \u003cline hits=\"1\" number=\"50\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"53\"/\u003e\n \u003cline hits=\"1\" number=\"54\"/\u003e\n \u003cline hits=\"1\" number=\"57\"/\u003e\n \u003cline hits=\"1\" number=\"61\"/\u003e\n \u003cline hits=\"1\" number=\"62\"/\u003e\n \u003cline hits=\"1\" number=\"65\"/\u003e\n \u003cline hits=\"1\" number=\"66\"/\u003e\n \u003cline hits=\"1\" number=\"69\"/\u003e\n \u003cline hits=\"1\" number=\"72\"/\u003e\n \u003cline hits=\"1\" number=\"73\"/\u003e\n \u003cline hits=\"1\" number=\"76\"/\u003e\n \u003cline hits=\"1\" number=\"78\"/\u003e\n \u003cline hits=\"1\" number=\"79\"/\u003e\n \u003cline hits=\"1\" number=\"81\"/\u003e\n \u003cline hits=\"1\" number=\"82\"/\u003e\n \u003cline hits=\"1\" number=\"84\"/\u003e\n \u003cline hits=\"1\" number=\"86\"/\u003e\n \u003cline hits=\"1\" number=\"90\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"94\"/\u003e\n \u003cline hits=\"1\" number=\"95\"/\u003e\n \u003cline hits=\"1\" number=\"99\"/\u003e\n \u003cline hits=\"1\" number=\"101\"/\u003e\n \u003cline hits=\"1\" number=\"104\"/\u003e\n \u003cline hits=\"1\" number=\"105\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"107\"/\u003e\n \u003cline hits=\"1\" number=\"108\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"110\"/\u003e\n \u003cline hits=\"1\" number=\"111\"/\u003e\n \u003cline hits=\"1\" number=\"113\"/\u003e\n \u003cline hits=\"1\" number=\"115\"/\u003e\n \u003cline hits=\"1\" number=\"120\"/\u003e\n \u003cline hits=\"1\" number=\"121\"/\u003e\n \u003cline hits=\"1\" number=\"122\"/\u003e\n \u003cline hits=\"1\" number=\"125\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"127\"/\u003e\n \u003cline hits=\"1\" number=\"128\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"50% (1/2)\" hits=\"1\" missing-branches=\"134\" number=\"130\"/\u003e\n \u003cline hits=\"1\" number=\"131\"/\u003e\n \u003cline hits=\"0\" number=\"134\"/\u003e\n \u003cline hits=\"1\" number=\"136\"/\u003e\n \u003cline hits=\"1\" number=\"139\"/\u003e\n \u003cline hits=\"1\" number=\"141\"/\u003e\n \u003cline hits=\"1\" number=\"144\"/\u003e\n \u003cline hits=\"1\" number=\"146\"/\u003e\n \u003cline hits=\"1\" number=\"149\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"151\"/\u003e\n \u003cline hits=\"1\" number=\"152\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"154\"/\u003e\n \u003cline hits=\"1\" number=\"155\"/\u003e\n \u003cline hits=\"1\" number=\"157\"/\u003e\n \u003c/lines\u003e\n \u003c/class\u003e\n \u003cclass branch-rate=\"1\" complexity=\"0\" filename=\"/code/s3tree/s3tree/exceptions.py\" line-rate=\"1\" name=\"exceptions.py\"\u003e\n \u003cmethods/\u003e\n \u003clines\u003e\n \u003cline hits=\"1\" number=\"5\"/\u003e\n \u003cline hits=\"1\" number=\"6\"/\u003e\n \u003cline hits=\"1\" number=\"7\"/\u003e\n \u003cline hits=\"1\" number=\"11\"/\u003e\n \u003cline hits=\"1\" number=\"14\"/\u003e\n \u003cline hits=\"1\" number=\"15\"/\u003e\n \u003cline hits=\"1\" number=\"16\"/\u003e\n \u003cline hits=\"1\" number=\"17\"/\u003e\n \u003cline hits=\"1\" number=\"20\"/\u003e\n \u003cline hits=\"1\" number=\"21\"/\u003e\n \u003cline hits=\"1\" number=\"22\"/\u003e\n \u003cline hits=\"1\" number=\"25\"/\u003e\n \u003cline hits=\"1\" number=\"28\"/\u003e\n \u003cline hits=\"1\" number=\"29\"/\u003e\n \u003cline hits=\"1\" number=\"30\"/\u003e\n \u003cline hits=\"1\" number=\"31\"/\u003e\n \u003cline hits=\"1\" number=\"34\"/\u003e\n \u003cline hits=\"1\" number=\"35\"/\u003e\n \u003cline hits=\"1\" number=\"36\"/\u003e\n \u003cline hits=\"1\" number=\"37\"/\u003e\n \u003cline hits=\"1\" number=\"40\"/\u003e\n \u003cline hits=\"1\" number=\"41\"/\u003e\n \u003cline hits=\"1\" number=\"42\"/\u003e\n \u003cline hits=\"1\" number=\"43\"/\u003e\n \u003c/lines\u003e\n \u003c/class\u003e\n \u003cclass branch-rate=\"1\" complexity=\"0\" filename=\"/code/s3tree/s3tree/models.py\" line-rate=\"0.9615\" name=\"models.py\"\u003e\n \u003cmethods/\u003e\n \u003clines\u003e\n \u003cline hits=\"1\" number=\"3\"/\u003e\n \u003cline hits=\"1\" number=\"5\"/\u003e\n \u003cline hits=\"1\" number=\"6\"/\u003e\n \u003cline hits=\"1\" number=\"7\"/\u003e\n \u003cline hits=\"1\" number=\"8\"/\u003e\n \u003cline hits=\"1\" number=\"9\"/\u003e\n \u003cline hits=\"1\" number=\"10\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"13\"/\u003e\n \u003cline hits=\"1\" number=\"14\"/\u003e\n \u003cline hits=\"1\" number=\"19\"/\u003e\n \u003cline hits=\"1\" number=\"20\"/\u003e\n \u003cline hits=\"1\" number=\"21\"/\u003e\n \u003cline hits=\"1\" number=\"23\"/\u003e\n \u003cline hits=\"1\" number=\"25\"/\u003e\n \u003cline hits=\"1\" number=\"27\"/\u003e\n \u003cline hits=\"1\" number=\"28\"/\u003e\n \u003cline hits=\"1\" number=\"30\"/\u003e\n \u003cline hits=\"1\" number=\"31\"/\u003e\n \u003cline hits=\"1\" number=\"37\"/\u003e\n \u003cline hits=\"1\" number=\"40\"/\u003e\n \u003cline hits=\"1\" number=\"45\"/\u003e\n \u003cline hits=\"1\" number=\"48\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"51\"/\u003e\n \u003cline hits=\"1\" number=\"52\"/\u003e\n \u003cline hits=\"1\" number=\"55\"/\u003e\n \u003cline hits=\"1\" number=\"57\"/\u003e\n \u003cline hits=\"1\" number=\"58\"/\u003e\n \u003cline hits=\"1\" number=\"59\"/\u003e\n \u003cline hits=\"1\" number=\"60\"/\u003e\n \u003cline hits=\"1\" number=\"61\"/\u003e\n \u003cline hits=\"1\" number=\"64\"/\u003e\n \u003cline hits=\"1\" number=\"67\"/\u003e\n \u003cline hits=\"1\" number=\"69\"/\u003e\n \u003cline hits=\"1\" number=\"72\"/\u003e\n \u003cline hits=\"1\" number=\"74\"/\u003e\n \u003cline hits=\"1\" number=\"77\"/\u003e\n \u003cline hits=\"1\" number=\"79\"/\u003e\n \u003cline hits=\"1\" number=\"82\"/\u003e\n \u003cline hits=\"1\" number=\"84\"/\u003e\n \u003cline hits=\"1\" number=\"86\"/\u003e\n \u003cline hits=\"1\" number=\"87\"/\u003e\n \u003cline hits=\"0\" number=\"90\"/\u003e\n \u003cline hits=\"0\" number=\"91\"/\u003e\n \u003cline hits=\"1\" number=\"93\"/\u003e\n \u003cline hits=\"1\" number=\"94\"/\u003e\n \u003cline hits=\"1\" number=\"96\"/\u003e\n \u003cline hits=\"1\" number=\"99\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"101\"/\u003e\n \u003cline hits=\"1\" number=\"102\"/\u003e\n \u003cline hits=\"1\" number=\"103\"/\u003e\n \u003cline hits=\"1\" number=\"105\"/\u003e\n \u003cline hits=\"1\" number=\"108\"/\u003e\n \u003c/lines\u003e\n \u003c/class\u003e\n \u003cclass branch-rate=\"0.5\" complexity=\"0\" filename=\"/code/s3tree/s3tree/types.py\" line-rate=\"1\" name=\"types.py\"\u003e\n \u003cmethods/\u003e\n \u003clines\u003e\n \u003cline hits=\"1\" number=\"3\"/\u003e\n \u003cline hits=\"1\" number=\"6\"/\u003e\n \u003cline hits=\"1\" number=\"8\"/\u003e\n \u003cline hits=\"1\" number=\"10\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"50% (1/2)\" hits=\"1\" missing-branches=\"14\" number=\"11\"/\u003e\n \u003cline hits=\"1\" number=\"12\"/\u003e\n \u003cline hits=\"1\" number=\"14\"/\u003e\n \u003cline hits=\"1\" number=\"17\"/\u003e\n \u003cline hits=\"1\" number=\"18\"/\u003e\n \u003cline hits=\"1\" number=\"21\"/\u003e\n \u003cline hits=\"1\" number=\"22\"/\u003e\n \u003cline hits=\"1\" number=\"23\"/\u003e\n \u003cline hits=\"1\" number=\"24\"/\u003e\n \u003c/lines\u003e\n \u003c/class\u003e\n \u003cclass branch-rate=\"1\" complexity=\"0\" filename=\"/code/s3tree/s3tree/utils.py\" line-rate=\"1\" name=\"utils.py\"\u003e\n \u003cmethods/\u003e\n \u003clines\u003e\n \u003cline hits=\"1\" number=\"3\"/\u003e\n \u003cline hits=\"1\" number=\"4\"/\u003e\n \u003cline hits=\"1\" number=\"5\"/\u003e\n \u003cline hits=\"1\" number=\"6\"/\u003e\n \u003cline hits=\"1\" number=\"8\"/\u003e\n \u003cline hits=\"1\" number=\"11\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"27\"/\u003e\n \u003cline hits=\"1\" number=\"28\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"30\"/\u003e\n \u003cline hits=\"1\" number=\"31\"/\u003e\n \u003cline hits=\"1\" number=\"34\"/\u003e\n \u003cline branch=\"true\" condition-coverage=\"100% (2/2)\" hits=\"1\" number=\"37\"/\u003e\n \u003cline hits=\"1\" number=\"38\"/\u003e\n \u003cline hits=\"1\" number=\"40\"/\u003e\n \u003cline hits=\"1\" number=\"43\"/\u003e\n \u003cline hits=\"1\" number=\"56\"/\u003e\n \u003cline hits=\"1\" number=\"60\"/\u003e\n \u003cline hits=\"1\" number=\"65\"/\u003e\n \u003cline hits=\"1\" number=\"69\"/\u003e\n \u003cline hits=\"1\" number=\"73\"/\u003e\n \u003cline hits=\"1\" number=\"74\"/\u003e\n \u003cline hits=\"1\" number=\"76\"/\u003e\n \u003cline hits=\"1\" number=\"78\"/\u003e\n \u003cline hits=\"1\" number=\"81\"/\u003e\n \u003cline hits=\"1\" number=\"83\"/\u003e\n \u003c/lines\u003e\n \u003c/class\u003e\n \u003c/classes\u003e\n \u003c/package\u003e\n \u003c/packages\u003e\n\u003c/coverage\u003e\n",
"analyzer": "test-coverage",
"analyzerType": "community",
"metadata": {
"workDir": "/home/runner/code",
"compressed": "True"
}
}
}
}
Loading
Loading