Skip to content
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
124 changes: 124 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Contributing

> This guide is for internal Snyk contributors with write access to this repository. If you are an external contributor, before working on any contributions, please first [contact support](https://support.snyk.io) to discuss the issue or feature request with us.

## Prerequisites

You will need the following software installed:

- Git
- Go
- Use whichever version is in [`go.mod`](./go.mod).

Open a terminal and make sure they are available.

```sh
git --version
go version
```

## Setting up

Clone this repository with git.

```sh
git clone git@github.com:snyk/code-client-go.git
cd code-client-go
```

You will now be on our `main` branch. You should never commit to this branch, but you should keep it up-to-date to ensure you have the latest changes.

```sh
git fetch
git pull --ff-only
```

## Running tests

To run the tests run:

```sh
make test
```

## Code ownership

For current ownership assignments, see: [CODEOWNERS](./.github/CODEOWNERS).

To avoid mixing ownership into a single file, move team-specific logic into separate files. To reduce blockers and save time, design with ownership in mind.

## Code formatting

To ensure your changes follow formatting guidelines, you can run the linter.

```
make lint
```

To fix various issues automatically you can run the following:

```
make format
```

You will need to fix any remaining issues manually.

## Creating a branch

Create a new branch before making any changes. Make sure to give it a descriptive name so that you can find it later.

```sh
git checkout -b type/topic
```

For example:

```sh
git checkout -b docs/contributing
```

## Creating commits

Each commit must provide some benefit on its own without breaking the release pipeline.

For larger changes, break down each step into multiple commits so that it's easy to review in pull requests and git history.

Commits must follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) structure:

```
type: summary of your changes

reasoning behind your changes
```

For example:

```
docs: update contributing guide

We often get questions on how to contribute to this repo. What versions to use, what the workflow is, and so on. This change updates our CONTRIBUTING guide to answer those types of questions.
```

### Commit types

The commit type is used to summarize intent and to automate various steps.

| Type | Description |
| ---------- | ----------------------------------------------- |
| `feat` | A new user-facing feature. |
| `fix` | A bug fix for an existing feature. |
| `refactor` | Changes which do not affect existing features. |
| `test` | Changes to tests for existing features. |
| `docs` | Changes to documentation for existing features. |
| `chore` | Build, workflow and pipeline changes. |
| `revert` | Reverting a previous commit. |

## Pushing changes

Once you have committed your changes, review them locally, then push them to GitHub.

```
git push
```

Do not hold onto your changes for too long. Commit and push frequently and create a pull request as soon as possible for backup and visibility.
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
module github.com/snyk/code-client-go

go 1.21.7

require github.com/stretchr/testify v1.8.4

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
178 changes: 178 additions & 0 deletions sarif_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
* © 2022 Snyk Limited All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package code_client_go

type SarifResponse struct {
Type string `json:"type"`
Progress float64 `json:"progress"`
Status string `json:"status"`
Timing struct {
FetchingCode int `json:"fetchingCode"`
Queue int `json:"queue"`
Analysis int `json:"analysis"`
} `json:"timing"`
Coverage []struct {
Files int `json:"files"`
IsSupported bool `json:"isSupported"`
Lang string `json:"lang"`
} `json:"coverage"`
Sarif struct {
Schema string `json:"$schema"`
Version string `json:"version"`
Runs []Run `json:"runs"`
} `json:"sarif"`
}

type region struct {
StartLine int `json:"startLine"`
EndLine int `json:"endLine"`
StartColumn int `json:"startColumn"`
EndColumn int `json:"endColumn"`
}

type ArtifactLocation struct {
URI string `json:"uri"`
URIBaseID string `json:"uriBaseId"`
}

type PhysicalLocation struct {
ArtifactLocation ArtifactLocation `json:"ArtifactLocation"`
Region region `json:"region"`
}

type Location struct {
ID int `json:"id"`
PhysicalLocation PhysicalLocation `json:"PhysicalLocation"`
}

type ThreadFlowLocation struct {
Location Location `json:"Location"`
}

type ThreadFlow struct {
Locations []ThreadFlowLocation `json:"locations"`
}

type CodeFlow struct {
ThreadFlows []ThreadFlow `json:"threadFlows"`
}

type ResultMessage struct {
Text string `json:"text"`
Markdown string `json:"markdown"`
Arguments []string `json:"arguments"`
}

type Fingerprints struct {
Num0 string `json:"0"`
Num1 string `json:"1"`
}

type ResultProperties struct {
PriorityScore int `json:"priorityScore"`
PriorityScoreFactors []struct {
Label bool `json:"label"`
Type string `json:"type"`
} `json:"priorityScoreFactors"`
IsAutofixable bool `json:"isAutofixable"`
}

type Result struct {
RuleID string `json:"ruleId"`
RuleIndex int `json:"ruleIndex"`
Level string `json:"level"`
Message ResultMessage `json:"message"`
Locations []Location `json:"locations"`
Fingerprints Fingerprints `json:"Fingerprints"`
CodeFlows []CodeFlow `json:"codeFlows"`
Properties ResultProperties `json:"properties"`
}

type ExampleCommitFix struct {
CommitURL string `json:"commitURL"`
Lines []struct {
Line string `json:"line"`
LineNumber int `json:"lineNumber"`
LineChange string `json:"lineChange"`
} `json:"lines"`
}

type Help struct {
Markdown string `json:"markdown"`
Text string `json:"text"`
}

type RuleProperties struct {
Tags []string `json:"tags"`
ShortDescription struct {
Text string `json:"text"`
} `json:"ShortDescription"`

Help struct {
Markdown string `json:"markdown"`
Text string `json:"text"`
} `json:"Help"`

Categories []string `json:"categories"`
ExampleCommitFixes []ExampleCommitFix `json:"exampleCommitFixes"`
ExampleCommitDescriptions []string `json:"exampleCommitDescriptions"`
Precision string `json:"precision"`
RepoDatasetSize int `json:"repoDatasetSize"`
Cwe []string `json:"cwe"`
}

type DefaultConfiguration struct {
Level string `json:"level"`
}

type ShortDescription struct {
Text string `json:"text"`
}

type Rule struct {
ID string `json:"id"`
Name string `json:"name"`
ShortDescription ShortDescription `json:"ShortDescription"`
DefaultConfiguration DefaultConfiguration `json:"DefaultConfiguration"`
Help Help `json:"Help"`
Properties RuleProperties `json:"properties"`
}

type Driver struct {
Name string `json:"name"`
SemanticVersion string `json:"semanticVersion"`
Version string `json:"version"`
Rules []Rule `json:"rules"`
}

type Tool struct {
Driver Driver `json:"Driver"`
}

type runProperties struct {
Coverage []struct {
Files int `json:"files"`
IsSupported bool `json:"isSupported"`
Lang string `json:"lang"`
} `json:"coverage"`
}

type Run struct {
Tool Tool `json:"Tool"`
Results []Result `json:"results"`
Properties runProperties `json:"RuleProperties"`
}
Loading