scm

package
v0.10.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

The functions in this file are responsible for building a slice of regular expressions base on patterns in a .gitignore file. The patterns are used to help the program adhere to the same rules that a .gitignore pattern applies to git repos. The result, we do not parse source code that does not need to be parsed. For example, we would never want to parse a god forsaken node modules folder!

Index

Constants

View Source
const (
	GITHUB    = "github"
	GITLAB    = "gitlab"
	BITBUCKET = "bitbucket"
)
View Source
const (
	BASE_URL           = "https://github.com"
	GITHUB_BASE_URL    = "https://api.github.com"
	CLIENT_ID          = "ca711ca70149e4948032"
	GRANT_TYPE         = "urn:ietf:params:oauth:grant-type:device_code"
	ACCESS_TOKEN       = "/access_token"
	SCOPES             = "repo"
	ACCEPT_JSON        = "application/json"
	ACCEPT_VDN         = "application/vnd.github+json"
	GITHUB_API_VERSION = "2022-11-28"
)

Variables

This section is empty.

Functions

func ExtractUserRepoName added in v0.10.3

func ExtractUserRepoName(out []byte) (string, string, error)

ExtractUserRepoName takes the output from <git remote --verbose> command as input and attempts to extract the user name and repository name from out

func ReadAccessToken added in v0.8.0

func ReadAccessToken(scm string) (string, error)

func WriteToken

func WriteToken(token string, scm string) error

WriteToken accepts an access token and the source code management platform (GitHub, GitLab etc...) and will write the token to a configuration file. This will be used to authorize future requests for reporting issues.

Types

type GitConfigManager

type GitConfigManager interface {
	Authorize() error
	Report(issues []GitIssue) <-chan int64
}

GitConfigManager provides flexibility to have different implementations of Authorize and Report for each source code management platform supported

func NewGitManager added in v0.10.0

func NewGitManager(scm, userName, repoName string) (GitConfigManager, error)

@TODO add other source code management structs to NewGitManager once their implementations are created

type GitHubManager

type GitHubManager struct {
	// contains filtered or unexported fields
}

func (*GitHubManager) Authorize

func (gh *GitHubManager) Authorize() error

Authorize satisfies the GitManager interface. Each source code management platform will have their own version of how to authorize so that the program can submit issues on the users behalf. This implementation uses GitHubs device oauth flow. See their docs for more detailed information. First, a user code is created and a browser opens to GitHubs verification url. While the program is waiting for the user to enter the code, we poll an endpoint and check if the user has authorized the app. Once they have done so, an access token is returned from the service and is then written to ~/.config/issue-summoner/config.json

func (*GitHubManager) Report added in v0.8.0

func (gh *GitHubManager) Report(issues []GitIssue) <-chan int64

type GitIssue added in v0.10.3

type GitIssue struct {
	Title string `json:"title"`
	Body  string `json:"body"`
}

type IgnorePattern added in v0.8.2

type IgnorePattern = regexp.Regexp

func ParseIgnorePatterns added in v0.8.2

func ParseIgnorePatterns(r io.Reader) ([]IgnorePattern, error)

@TODO .gitignore path validation rules are broken Throughout some testing on large open source projects, I have found the effectiveness of- ignoring paths largely unsuccessful. There are edge cases we need to bake into these functions:

1. (!) Prefix to negate patterns. Matching files excluded by previous patters will become included again.

2. (/) Separator placement. Beginning, middle (or both) means the path pattern is relative to the directory level of the gitignore file. If the separator is at the end, the pattern should match directories or files

3. (*) Asterisk matches anything except a slash.

4. (?) Matches any one character except "/"

5. [a-zA-Z] Range notation can be used to match one of the characters in a range

6. (**) Leading/Trailing Double Asterisks

7. Sub directories may contain their own gitignore file. Account for this.

This initial implementation was quick and dirty and it worked for small projects. However, it is now causing issues and may lead to some files/directories not being scanned at all or scanning files/dirs that shouldn't be scanned.

type IssueSummonerConfig

type IssueSummonerConfig = map[string]ScmTokenConfig

type ScmTokenConfig

type ScmTokenConfig struct {
	AccessToken string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL