From 88e84f2bbefc533125e68cc074c1157ec2b9ff48 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Fri, 29 Nov 2024 14:10:44 +0100 Subject: [PATCH] more cleanup --- filter/filter.go | 7 ++-- gitlab/gitlab.go | 96 ------------------------------------------------ gitlab/repo.go | 62 ------------------------------- 3 files changed, 3 insertions(+), 162 deletions(-) delete mode 100644 gitlab/gitlab.go delete mode 100644 gitlab/repo.go diff --git a/filter/filter.go b/filter/filter.go index 891a5965..e8239824 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -17,9 +17,8 @@ package filter import ( "fmt" - "github.com/segmentio/encoding/json" - "github.com/miku/span/formats/finc" + "github.com/segmentio/encoding/json" ) // Filter returns go or no for a given record. @@ -51,8 +50,8 @@ func (t *Tree) Apply(is finc.IntermediateSchema) bool { return t.Root.Apply(is) } -// Tagger takes a list of tags (ISILs) and annotates an intermediate schema -// according to a number of filters, defined per label. The tagger is loaded +// Tagger takes a list of labels (ISILs) and annotates an intermediate schema +// according to a number of filters, defined per labels The tagger is loaded // directly from JSON. type Tagger struct { FilterMap map[string]Tree diff --git a/gitlab/gitlab.go b/gitlab/gitlab.go deleted file mode 100644 index 3dd21e00..00000000 --- a/gitlab/gitlab.go +++ /dev/null @@ -1,96 +0,0 @@ -// Package gitlab contains support types for gitlab interaction. -package gitlab - -import ( - "regexp" -) - -// PushPayload delivered on push and web edits. This is the whole response, we -// are mainly interested in the modified files in a commit. -type PushPayload struct { - After string `json:"after"` - Before string `json:"before"` - CheckoutSha string `json:"checkout_sha"` - Commits []struct { - Added []interface{} `json:"added"` - Author struct { - Email string `json:"email"` - Name string `json:"name"` - } `json:"author"` - Id string `json:"id"` - Message string `json:"message"` - Modified []string `json:"modified"` - Removed []interface{} `json:"removed"` - Timestamp string `json:"timestamp"` - Url string `json:"url"` - } `json:"commits"` - EventName string `json:"event_name"` - Message interface{} `json:"message"` - ObjectKind string `json:"object_kind"` - Project struct { - AvatarUrl interface{} `json:"avatar_url"` - CiConfigPath interface{} `json:"ci_config_path"` - DefaultBranch string `json:"default_branch"` - Description string `json:"description"` - GitHttpUrl string `json:"git_http_url"` - GitSshUrl string `json:"git_ssh_url"` - Homepage string `json:"homepage"` - HttpUrl string `json:"http_url"` - Id int64 `json:"id"` - Name string `json:"name"` - Namespace string `json:"namespace"` - PathWithNamespace string `json:"path_with_namespace"` - SshUrl string `json:"ssh_url"` - Url string `json:"url"` - VisibilityLevel int64 `json:"visibility_level"` - WebUrl string `json:"web_url"` - } `json:"project"` - ProjectId int64 `json:"project_id"` - Ref string `json:"ref"` - Repository struct { - Description string `json:"description"` - GitHttpUrl string `json:"git_http_url"` - GitSshUrl string `json:"git_ssh_url"` - Homepage string `json:"homepage"` - Name string `json:"name"` - Url string `json:"url"` - VisibilityLevel int64 `json:"visibility_level"` - } `json:"repository"` - TotalCommitsCount int64 `json:"total_commits_count"` - UserAvatar string `json:"user_avatar"` - UserEmail string `json:"user_email"` - UserId int64 `json:"user_id"` - UserName string `json:"user_name"` - UserUsername string `json:"user_username"` -} - -// ModifiedFiles returns all modified files across all commits in this payload. -func (p PushPayload) ModifiedFiles() (filenames []string) { - for _, commit := range p.Commits { - for _, modified := range commit.Modified { - filenames = append(filenames, modified) - } - } - return -} - -// IsFileModified returns true, if given file has been modified. -func (p PushPayload) IsFileModified(filename string) bool { - for _, modified := range p.ModifiedFiles() { - if modified == filename { - return true - } - } - return false -} - -// MatchModified returns a list of paths matching a pattern (match against the -// full path in repo, e.g. docs/review.*). -func (p PushPayload) MatchModified(re *regexp.Regexp) (filenames []string) { - for _, modified := range p.ModifiedFiles() { - if re.MatchString(modified) { - filenames = append(filenames, modified) - } - } - return -} diff --git a/gitlab/repo.go b/gitlab/repo.go deleted file mode 100644 index d66175d6..00000000 --- a/gitlab/repo.go +++ /dev/null @@ -1,62 +0,0 @@ -package gitlab - -import ( - "fmt" - "log" - "os" - "os/exec" - "path" - "strings" -) - -// Repo connects a remote git repository to a local clone. Remote -// authentification via token (e.g. in gitlab) supported. -type Repo struct { - URL string - Dir string - Token string -} - -// AuthURL returns an authenticated repository URL, if no token is supplied, -// just return the repo URL as is. -func (r Repo) AuthURL() string { - if r.Token == "" { - return r.URL - } - return strings.Replace(r.URL, "https://", fmt.Sprintf("https://oauth2:%s@", r.Token), 1) -} - -// String representation. -func (r Repo) String() string { - return fmt.Sprintf("git repo from %s at %s", r.URL, r.Dir) -} - -// Update runs a git pull (or clone), as per strong convention, this will -// always be a fast forward. If repo does not exist yet, clone. -// gitlab/profile/personal_access_tokens: You can also use personal access -// tokens to authenticate against Git over HTTP. They are the only accepted -// password when you have Two-Factor Authentication (2FA) enabled. -func (r Repo) Update() error { - log.Printf("updating %s", r) - if r.Token == "" { - log.Printf("no gitlab.token found, checkout might fail") - } - if _, err := os.Stat(path.Dir(r.Dir)); os.IsNotExist(err) { - if err := os.MkdirAll(path.Dir(r.Dir), 0755); err != nil { - return err - } - } - var ( - cmd string - args []string - ) - if _, err := os.Stat(r.Dir); os.IsNotExist(err) { - cmd, args = "git", []string{"clone", r.AuthURL(), r.Dir} - } else { - cmd, args = "git", []string{"-C", r.Dir, "pull", "origin", "master"} - } - // TODO: black out token for logs. - log.Printf("[cmd] %s %s", cmd, strings.Join(args, " ")) - // TODO: exit code handling, https://stackoverflow.com/a/10385867. - return exec.Command(cmd, args...).Run() -}