Skip to content

Commit

Permalink
freeze-ancient-issues: parse issue repo from URL
Browse files Browse the repository at this point in the history
Issues returned from GitHub Search API do not contain the Repository
field so the previous code was crashing
  • Loading branch information
parkr committed Apr 23, 2019
1 parent e782ff1 commit fd19016
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cmd/freeze-ancient-issues/main.go
Expand Up @@ -151,16 +151,18 @@ func processRepo(context *ctx.Context, owner, repo string, actuallyDoIt bool) er
func processIssues(context *ctx.Context, actuallyDoIt bool, issues []github.Issue) error {
for _, issue := range issues {
context.Log("processing issue: %#v", issue)
owner := issue.GetRepository().GetOwner().GetLogin()
repo := issue.GetRepository().GetName()
repo, err := jekyll.ParseRepositoryFromURL(issue.GetHTMLURL())
if err != nil {
return err
}
if actuallyDoIt {
log.Printf("%s/%s: freezing %s", owner, repo, issue.GetHTMLURL())
if err := freeze.Freeze(context, owner, repo, issue.GetNumber()); err != nil {
log.Printf("%s/%s: freezing %s", repo.Owner(), repo.Name(), issue.GetHTMLURL())
if err := freeze.Freeze(context, repo.Owner(), repo.Name(), issue.GetNumber()); err != nil {
return err
}
time.Sleep(sleepBetweenFreezes)
} else {
log.Printf("%s/%s: would have frozen %s", owner, repo, issue.GetHTMLURL())
log.Printf("%s/%s: would have frozen %s", repo.Owner(), repo.Name(), issue.GetHTMLURL())
time.Sleep(sleepBetweenFreezes)
}
}
Expand Down
13 changes: 13 additions & 0 deletions jekyll/repos.go
@@ -1,6 +1,7 @@
package jekyll

import (
"net/url"
"strings"

"github.com/pkg/errors"
Expand Down Expand Up @@ -32,6 +33,18 @@ func ParseRepository(repoNWO string) (Repository, error) {
return NewRepository(pieces[0], pieces[1]), nil
}

func ParseRepositoryFromURL(urlStr string) (Repository, error) {
u, err := url.Parse(urlStr)
if err != nil {
return nil, err
}
pieces := strings.Split(u.Path, "/")
if len(pieces) < 2 {
return nil, errors.Errorf("url has no repo: %q", urlStr)
}
return NewRepository(pieces[0], pieces[1]), nil
}

func NewRepository(owner, repo string) Repository {
return GitHubRepository{owner, repo}
}
Expand Down

0 comments on commit fd19016

Please sign in to comment.