зеркало из https://github.com/golang/build.git
maintner: rename GithubRepoID to GitHubRepoID
Make the naming a little more consistent. Change-Id: Icd40d3818c490fa0bd1562a924a684d79c17c4a4 Reviewed-on: https://go-review.googlesource.com/59590 Reviewed-by: Andrew Bonventre <andybons@golang.org>
This commit is contained in:
Родитель
87bcf520b4
Коммит
b60cce42b1
|
@ -139,7 +139,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
req = stripPrefix(req, baseURLLen)
|
||||
h.serveIssues(w, req, maintner.GithubRepoID{Owner: owner, Repo: repo})
|
||||
h.serveIssues(w, req, maintner.GitHubRepoID{Owner: owner, Repo: repo})
|
||||
}
|
||||
|
||||
var indexHTML = template.Must(template.New("").Parse(`<html>
|
||||
|
@ -164,7 +164,7 @@ var indexHTML = template.Must(template.New("").Parse(`<html>
|
|||
// serveIndex serves the index page, which lists all available repositories.
|
||||
func (h *handler) serveIndex(w http.ResponseWriter, req *http.Request) {
|
||||
type repo struct {
|
||||
RepoID maintner.GithubRepoID
|
||||
RepoID maintner.GitHubRepoID
|
||||
Count uint64 // Issues count.
|
||||
}
|
||||
var repos []repo
|
||||
|
@ -208,7 +208,7 @@ func countIssues(r *maintner.GitHubRepo) (uint64, error) {
|
|||
}
|
||||
|
||||
// serveIssues serves issues for repository id.
|
||||
func (h *handler) serveIssues(w http.ResponseWriter, req *http.Request, id maintner.GithubRepoID) {
|
||||
func (h *handler) serveIssues(w http.ResponseWriter, req *http.Request, id maintner.GitHubRepoID) {
|
||||
if h.c.GitHub().Repo(id.Owner, id.Repo) == nil {
|
||||
http.Error(w, fmt.Sprintf("404 Not Found\n\nrepository %q not found", id), http.StatusNotFound)
|
||||
return
|
||||
|
|
|
@ -34,14 +34,14 @@ import (
|
|||
// package for responses fulfilled from cache due to a 304 from the server.
|
||||
const xFromCache = "X-From-Cache"
|
||||
|
||||
// GithubRepoID is a github org & repo, lowercase.
|
||||
type GithubRepoID struct {
|
||||
// GitHubRepoID is a github org & repo, lowercase.
|
||||
type GitHubRepoID struct {
|
||||
Owner, Repo string
|
||||
}
|
||||
|
||||
func (id GithubRepoID) String() string { return id.Owner + "/" + id.Repo }
|
||||
func (id GitHubRepoID) String() string { return id.Owner + "/" + id.Repo }
|
||||
|
||||
func (id GithubRepoID) valid() bool {
|
||||
func (id GitHubRepoID) valid() bool {
|
||||
if id.Owner == "" || id.Repo == "" {
|
||||
// TODO: more validation. whatever github requires.
|
||||
return false
|
||||
|
@ -53,14 +53,14 @@ func (id GithubRepoID) valid() bool {
|
|||
type GitHub struct {
|
||||
c *Corpus
|
||||
users map[int64]*GitHubUser
|
||||
repos map[GithubRepoID]*GitHubRepo
|
||||
repos map[GitHubRepoID]*GitHubRepo
|
||||
}
|
||||
|
||||
// ForeachRepo calls fn serially for each GithubRepo, stopping if fn
|
||||
// returns an error. The function is called with lexically increasing
|
||||
// repo IDs.
|
||||
func (g *GitHub) ForeachRepo(fn func(*GitHubRepo) error) error {
|
||||
var ids []GithubRepoID
|
||||
var ids []GitHubRepoID
|
||||
for id := range g.repos {
|
||||
ids = append(ids, id)
|
||||
}
|
||||
|
@ -80,14 +80,14 @@ func (g *GitHub) ForeachRepo(fn func(*GitHubRepo) error) error {
|
|||
|
||||
// Repo returns the repo if it's known. Otherwise it returns nil.
|
||||
func (g *GitHub) Repo(owner, repo string) *GitHubRepo {
|
||||
return g.repos[GithubRepoID{owner, repo}]
|
||||
return g.repos[GitHubRepoID{owner, repo}]
|
||||
}
|
||||
|
||||
func (g *GitHub) getOrCreateRepo(owner, repo string) *GitHubRepo {
|
||||
if g == nil {
|
||||
panic("cannot call methods on nil GitHub")
|
||||
}
|
||||
id := GithubRepoID{owner, repo}
|
||||
id := GitHubRepoID{owner, repo}
|
||||
if !id.valid() {
|
||||
return nil
|
||||
}
|
||||
|
@ -106,13 +106,13 @@ func (g *GitHub) getOrCreateRepo(owner, repo string) *GitHubRepo {
|
|||
|
||||
type GitHubRepo struct {
|
||||
github *GitHub
|
||||
id GithubRepoID
|
||||
id GitHubRepoID
|
||||
issues map[int32]*GitHubIssue // num -> issue
|
||||
milestones map[int64]*GitHubMilestone
|
||||
labels map[int64]*GitHubLabel
|
||||
}
|
||||
|
||||
func (gr *GitHubRepo) ID() GithubRepoID { return gr.id }
|
||||
func (gr *GitHubRepo) ID() GitHubRepoID { return gr.id }
|
||||
|
||||
// Issue returns the the provided issue number, or nil if it's not known.
|
||||
func (gr *GitHubRepo) Issue(n int32) *GitHubIssue { return gr.issues[n] }
|
||||
|
@ -595,7 +595,7 @@ func (c *Corpus) initGithub() {
|
|||
}
|
||||
c.github = &GitHub{
|
||||
c: c,
|
||||
repos: map[GithubRepoID]*GitHubRepo{},
|
||||
repos: map[GitHubRepoID]*GitHubRepo{},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,10 +80,10 @@ func TestProcessMutation_Github_NewIssue(t *testing.T) {
|
|||
github.users = map[int64]*GitHubUser{
|
||||
u1.ID: u1,
|
||||
}
|
||||
github.repos = map[GithubRepoID]*GitHubRepo{
|
||||
GithubRepoID{"golang", "go"}: &GitHubRepo{
|
||||
github.repos = map[GitHubRepoID]*GitHubRepo{
|
||||
GitHubRepoID{"golang", "go"}: &GitHubRepo{
|
||||
github: github,
|
||||
id: GithubRepoID{"golang", "go"},
|
||||
id: GitHubRepoID{"golang", "go"},
|
||||
issues: map[int32]*GitHubIssue{
|
||||
3: &GitHubIssue{
|
||||
Number: 3,
|
||||
|
@ -116,10 +116,10 @@ func TestProcessMutation_Github(t *testing.T) {
|
|||
c := new(Corpus)
|
||||
github := &GitHub{c: c}
|
||||
c.github = github
|
||||
github.repos = map[GithubRepoID]*GitHubRepo{
|
||||
GithubRepoID{"golang", "go"}: &GitHubRepo{
|
||||
github.repos = map[GitHubRepoID]*GitHubRepo{
|
||||
GitHubRepoID{"golang", "go"}: &GitHubRepo{
|
||||
github: github,
|
||||
id: GithubRepoID{"golang", "go"},
|
||||
id: GitHubRepoID{"golang", "go"},
|
||||
issues: make(map[int32]*GitHubIssue),
|
||||
},
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ func TestNewMutationsFromIssue(t *testing.T) {
|
|||
State: github.String("closed"),
|
||||
}
|
||||
gr := &GitHubRepo{
|
||||
id: GithubRepoID{"golang", "go"},
|
||||
id: GitHubRepoID{"golang", "go"},
|
||||
}
|
||||
is := gr.newMutationFromIssue(nil, gh)
|
||||
want := &maintpb.Mutation{GithubIssue: &maintpb.GithubIssueMutation{
|
||||
|
@ -186,7 +186,7 @@ func TestAssigneesDeleted(t *testing.T) {
|
|||
Assignees: assignees,
|
||||
}
|
||||
gr := &GitHubRepo{
|
||||
id: GithubRepoID{"golang", "go"},
|
||||
id: GitHubRepoID{"golang", "go"},
|
||||
issues: map[int32]*GitHubIssue{
|
||||
3: issue,
|
||||
},
|
||||
|
@ -195,8 +195,8 @@ func TestAssigneesDeleted(t *testing.T) {
|
|||
users: map[int64]*GitHubUser{
|
||||
u1.ID: u1,
|
||||
},
|
||||
repos: map[GithubRepoID]*GitHubRepo{
|
||||
GithubRepoID{"golang", "go"}: gr,
|
||||
repos: map[GitHubRepoID]*GitHubRepo{
|
||||
GitHubRepoID{"golang", "go"}: gr,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче