scm

package
v0.8.5 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 17 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 (
	GH = "github"
	GL = "gitlab"
	BB = "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 CheckForAccess added in v0.7.0

func CheckForAccess(scm string) (bool, error)

@TODO refactor WriteToken & CheckForAccess functions. There is some DRY code in the two functions that I would like to refactor. Specifically for getting the current directory, home dir and joining the paths for the configuration file.

func GlobalUserName added in v0.8.0

func GlobalUserName() (string, error)

GlobalUserName uses the **git config** command to retrieve the global configuration options. Specifically, the user.name option. The userName is read and set onto the reciever's (GitConfig) UserName property. This will be used

func ReadAccessToken added in v0.8.0

func ReadAccessToken(scm string) (string, error)

func RepoName added in v0.8.0

func RepoName() (string, error)

@TODO write unit test for RepoName/extractRepoName function.

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 GitConfig

type GitConfig struct {
	UserName       string
	RepositoryName string
	Token          string
	Scm            string // GitHub || GitLab || BitBucket ...
}

type GitConfigManager

type GitConfigManager interface {
	Authorize() error
	Report(issues []Issue, scm string) error
	IsAuthorized() (bool, error)
}

GitConfigManager interface allows us to have different adapters for each source code management system that we would like to use. We can have different implementations for GitHub, GitLab, BitBucket and so on. Authorize creates an access token with scopes that will allow us to read/write issues ReadToken checks if there is an access token in ~/.config/issue-summoner/config.json

func GetGitConfig

func GetGitConfig(scm string) GitConfigManager

type GitHubManager

type GitHubManager struct{}

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) IsAuthorized

func (gh *GitHubManager) IsAuthorized() (bool, error)

@TODO do we still need the IsAuthorized func? there is a check in git.go that validates if the user has an access token

func (*GitHubManager) Report added in v0.8.0

func (gh *GitHubManager) Report(issues []Issue, scm string) error

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 add ! (not) operator support for ignoring specific files/directories.

The ParseIgnorePatterns can handle most of the common patterns found in a gitignore file. However, there are scenarios where this function will fail to build proper regexps. Here is an example of some patterns that are not yet supported:

1. Ignore files in a specific directory, but not its subdirectories: directory_to_ignore/* !directory_to_ignore/*

2. Ignore files in a specific directory, except for one specific file: directory_to_ignore/* !directory_to_ignore/exception_file.txt

3. Ignore all files in a directory, including hidden files: directory_to_ignore/** !directory_to_ignore/ !directory_to_ignore/*

type Issue added in v0.8.0

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

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