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
- func CheckForAccess(scm string) (bool, error)
- func GlobalUserName() (string, error)
- func ReadAccessToken(scm string) (string, error)
- func RepoName() (string, error)
- func WriteToken(token string, scm string) error
- type GitConfig
- type GitConfigManager
- type GitHubManager
- type IgnorePattern
- type Issue
- type IssueSummonerConfig
- type ScmTokenConfig
Constants ¶
const ( GH = "github" GL = "gitlab" BB = "bitbucket" )
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
@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
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 WriteToken ¶
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 []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 NewGitManager ¶ added in v0.10.0
func NewGitManager(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
type IgnorePattern ¶ added in v0.8.2
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 func can handle most of the common patterns found in a gitignore file. However, there are scenarios where this function will fail to build proper expressions and cause the program to crash. I've tested on many open source projects and for some we cannot run the program at all. We should resolve this immediately. Here is an example of some patterns that are not yet supported:
1. Ignore files in a specific directory, but not its sub-directories: 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 IssueSummonerConfig ¶
type IssueSummonerConfig = map[string]ScmTokenConfig
type ScmTokenConfig ¶
type ScmTokenConfig struct {
AccessToken string
}