Skip to content
Open
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
6 changes: 3 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:

steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
uses: actions/setup-go@v6
with:
go-version: ^1.18
go-version: '1.25.5'

- name: Check out code into the Go module directory
uses: actions/checkout@v2
uses: actions/checkout@v6
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.head.sha }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v6
with:
fetch-depth: 0
submodules: 'true'

- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v6
with:
go-version: 1.21
go-version: '1.25.5'

- name: Setup environment variables
run: |-
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PACKAGE_NAME := github.com/deepsourcelabs/cli
GOLANG_CROSS_VERSION ?= v1.21.6
GOLANG_CROSS_VERSION ?= v1.25.3

SYSROOT_DIR ?= sysroots
SYSROOT_ARCHIVE ?= sysroots.tar.bz2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Usage:
deepsource <command> [<arguments>]

Available commands are:
report Report an artifact to an analyzer
auth Authenticate with DeepSource
config Generate and Validate DeepSource config
help Help about any command
issues Show the list of issues in a file in a repository
Expand Down
5 changes: 2 additions & 3 deletions command/config/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -60,9 +59,9 @@ func (o *Options) Run() error {
}

// Read the config in the form of string and send it
content, err := ioutil.ReadFile(configPath)
content, err := os.ReadFile(configPath)
if err != nil {
return errors.New("Error occured while reading DeepSource config file. Exiting...")
return fmt.Errorf("error occured while reading DeepSource config file %s: %w", configPath, err)
}

// Fetch the client
Expand Down
3 changes: 1 addition & 2 deletions command/issues/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/csv"
"encoding/json"
"fmt"
"io/ioutil"
"os"

"github.com/MakeNowJust/heredoc"
Expand Down Expand Up @@ -237,7 +236,7 @@ func (opts *IssuesListOptions) exportJSON(filename string) (err error) {
return nil
}

if err = ioutil.WriteFile(filename, data, 0o644); err != nil {
if err = os.WriteFile(filename, data, 0o644); err != nil {
return err
}

Expand Down
38 changes: 27 additions & 11 deletions command/issues/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package list

import (
"encoding/json"
"io/ioutil"
"os"
"reflect"
"strings"
Expand All @@ -13,9 +12,14 @@ import (

// Helper function to read issues from a file.
func ReadIssues(path string) []issues.Issue {
raw, _ := ioutil.ReadFile(path)
raw, err := os.ReadFile(path)
if err != nil {
panic(err)
}
var fetchedIssues []issues.Issue
_ = json.Unmarshal(raw, &fetchedIssues)
if err := json.Unmarshal(raw, &fetchedIssues); err != nil {
panic(err)
}

return fetchedIssues
}
Expand All @@ -26,8 +30,14 @@ func TestListCSV(t *testing.T) {
opts.exportCSV("./testdata/exported.csv")

// read exported and test CSV files
exported, _ := ioutil.ReadFile("./testdata/exported.csv")
test, _ := ioutil.ReadFile("./testdata/csv/test.csv")
exported, err := os.ReadFile("./testdata/exported.csv")
if err != nil {
t.Fatal(err)
}
test, err := os.ReadFile("./testdata/csv/test.csv")
if err != nil {
t.Fatal(err)
}

// trim carriage returns
got := strings.TrimSuffix(string(exported), "\n")
Expand All @@ -47,8 +57,14 @@ func TestListJSON(t *testing.T) {
opts.exportJSON("./testdata/exported.json")

// read exported and test JSON files
exported, _ := ioutil.ReadFile("./testdata/exported.json")
test, _ := ioutil.ReadFile("./testdata/json/test.json")
exported, err := os.ReadFile("./testdata/exported.json")
if err != nil {
t.Fatal(err)
}
test, err := os.ReadFile("./testdata/json/test.json")
if err != nil {
t.Fatal(err)
}

// trim carriage returns
got := strings.TrimSuffix(string(exported), "\n")
Expand All @@ -71,8 +87,8 @@ func TestListSARIF(t *testing.T) {
opts.exportSARIF("./testdata/exported.sarif")

// read exported and test SARIF files
exported, _ := ioutil.ReadFile("./testdata/exported.sarif")
test, _ := ioutil.ReadFile("./testdata/sarif/test.sarif")
exported, _ := os.ReadFile("./testdata/exported.sarif")
test, _ := os.ReadFile("./testdata/sarif/test.sarif")

// trim carriage returns
got := strings.TrimSuffix(string(exported), "\n")
Expand All @@ -94,8 +110,8 @@ func TestListSARIF(t *testing.T) {
opts.exportSARIF("./testdata/exported_multi.sarif")

// read exported and test SARIF files
exported, _ := ioutil.ReadFile("./testdata/exported_multi.sarif")
test, _ := ioutil.ReadFile("./testdata/sarif/test_multi.sarif")
exported, _ := os.ReadFile("./testdata/exported_multi.sarif")
test, _ := os.ReadFile("./testdata/sarif/test_multi.sarif")

// trim carriage returns
got := strings.TrimSuffix(string(exported), "\n")
Expand Down
6 changes: 3 additions & 3 deletions command/issues/list/testdata/sarif/test.sarif
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"version": "2.1.0",
"$schema": "https://json.schemastore.org/sarif-2.1.0-rtm.5.json",
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json",
"runs": [
{
"tool": {
"driver": {
"informationUri": "https://deepsource.io/directory/analyzers/go",
"informationUri": "https://deepsource.com/directory/analyzers/go",
"name": "DeepSource Go Analyzer",
"rules": [
{
Expand All @@ -15,7 +15,7 @@
"fullDescription": {
"text": ""
},
"helpUri": "https://deepsource.io/directory/analyzers/go/issues/RVV-B0013",
"helpUri": "https://deepsource.com/directory/analyzers/go/issues/RVV-B0013",
"properties": {
"category": "",
"recommended": ""
Expand Down
14 changes: 7 additions & 7 deletions command/issues/list/testdata/sarif/test_multi.sarif
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"version": "2.1.0",
"$schema": "https://json.schemastore.org/sarif-2.1.0-rtm.5.json",
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/main/sarif-2.1/schema/sarif-schema-2.1.0.json",
"runs": [
{
"tool": {
"driver": {
"informationUri": "https://deepsource.io/directory/analyzers/go",
"informationUri": "https://deepsource.com/directory/analyzers/go",
"name": "DeepSource Go Analyzer",
"rules": [
{
Expand All @@ -15,7 +15,7 @@
"fullDescription": {
"text": ""
},
"helpUri": "https://deepsource.io/directory/analyzers/go/issues/RVV-B0013",
"helpUri": "https://deepsource.com/directory/analyzers/go/issues/RVV-B0013",
"properties": {
"category": "",
"recommended": ""
Expand Down Expand Up @@ -74,7 +74,7 @@
{
"tool": {
"driver": {
"informationUri": "https://deepsource.io/directory/analyzers/docker",
"informationUri": "https://deepsource.com/directory/analyzers/docker",
"name": "DeepSource Docker Analyzer",
"rules": [
{
Expand All @@ -84,7 +84,7 @@
"fullDescription": {
"text": ""
},
"helpUri": "https://deepsource.io/directory/analyzers/docker/issues/DOK-DL3025",
"helpUri": "https://deepsource.com/directory/analyzers/docker/issues/DOK-DL3025",
"properties": {
"category": "",
"recommended": ""
Expand Down Expand Up @@ -121,7 +121,7 @@
{
"tool": {
"driver": {
"informationUri": "https://deepsource.io/directory/analyzers/python",
"informationUri": "https://deepsource.com/directory/analyzers/python",
"name": "DeepSource Python Analyzer",
"rules": [
{
Expand All @@ -131,7 +131,7 @@
"fullDescription": {
"text": ""
},
"helpUri": "https://deepsource.io/directory/analyzers/python/issues/PY-W2000",
"helpUri": "https://deepsource.com/directory/analyzers/python/issues/PY-W2000",
"properties": {
"category": "",
"recommended": ""
Expand Down
9 changes: 6 additions & 3 deletions command/issues/list/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

"github.com/deepsourcelabs/cli/deepsource/issues"
"github.com/owenrumney/go-sarif/v2/sarif"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

type ExportData struct {
Expand Down Expand Up @@ -164,10 +166,11 @@ func convertSARIF(issueData []issues.Issue) *sarif.Report {
count := 0

// Adding the tools data to the SARIF report corresponding to the number of analyzers activated
caser := cases.Title(language.English)
for _, issue := range issueData {
if !shortcodes[issue.Analyzer.Shortcode].exists {
driverName := "DeepSource " + strings.Title(issue.Analyzer.Shortcode) + " Analyzer"
informationURI := "https://deepsource.io/directory/analyzers/" + string(issue.Analyzer.Shortcode)
driverName := "DeepSource " + caser.String(issue.Analyzer.Shortcode) + " Analyzer"
informationURI := "https://deepsource.com/directory/" + string(issue.Analyzer.Shortcode)

tool := sarif.Tool{
Driver: &sarif.ToolComponent{
Expand Down Expand Up @@ -206,7 +209,7 @@ func convertSARIF(issueData []issues.Issue) *sarif.Report {
pb.Add("category", "")
pb.Add("recommended", "")

helpURI := "https://deepsource.io/directory/analyzers/" + string(issue.Analyzer.Shortcode) + "/issues/" + string(issue.IssueCode)
helpURI := "https://deepsource.com/directory/" + string(issue.Analyzer.Shortcode) + "/issues/" + string(issue.IssueCode)

// add rule
runs[idx].AddRule(issue.IssueCode).WithName(issue.IssueText).WithFullDescription(&fullDescription).WithHelpURI(helpURI).WithProperties(pb.Properties)
Expand Down
16 changes: 5 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
ConfigFileName = "/config.toml"
DefaultHostName = "deepsource.io"
)
const configDirPermissions os.FileMode = 0700

type CLIConfig struct {
Host string `toml:"host"`
Expand Down Expand Up @@ -111,7 +112,7 @@ func (cfg *CLIConfig) WriteFile() error {
return err
}

if err := os.MkdirAll(configDir, os.ModePerm); err != nil {
if err := os.MkdirAll(configDir, configDirPermissions); err != nil {
return err
}

Expand All @@ -120,16 +121,9 @@ func (cfg *CLIConfig) WriteFile() error {
return err
}

// Create file
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()

_, err = file.Write(data)

return err
// Write file with restricted permissions
const configFilePermissions os.FileMode = 0600
return os.WriteFile(path, data, configFilePermissions)
}

// Deletes the config during logging out user
Expand Down
18 changes: 13 additions & 5 deletions deepsource/tests/get_analyzers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package tests

import (
"context"
"io/ioutil"
"io"
"log"
"net/http"
"os"
"reflect"
"testing"

Expand Down Expand Up @@ -46,24 +47,31 @@ func TestAnalyzers(t *testing.T) {

// a mock GraphQL handler for testing
func mockAnalyzer(w http.ResponseWriter, r *http.Request) {
req, _ := ioutil.ReadAll(r.Body)
req, err := io.ReadAll(r.Body)
if err != nil {
log.Println(err)
http.Error(w, "Failed to read request body", http.StatusInternalServerError)
return
}

// Read test graphql request body artifact file
requestBodyData, err := ioutil.ReadFile("./testdata/analyzer/request_body.txt")
requestBodyData, err := os.ReadFile("./testdata/analyzer/request_body.txt")
if err != nil {
log.Println(err)
http.Error(w, "Failed to read test data", http.StatusInternalServerError)
return
}

// Read test graphql success response body artifact file
successResponseBodyData, err := ioutil.ReadFile("./testdata/analyzer/success_response_body.json")
successResponseBodyData, err := os.ReadFile("./testdata/analyzer/success_response_body.json")
if err != nil {
log.Println(err)
http.Error(w, "Failed to read test data", http.StatusInternalServerError)
return
}

// Read test graphql error response body artifact file
errorResponseBodyData, err := ioutil.ReadFile("./testdata/analyzer/error_response_body.json")
errorResponseBodyData, err := os.ReadFile("./testdata/analyzer/error_response_body.json")
if err != nil {
log.Println(err)
return
Expand Down
Loading
Loading