func (db Dashboard) readRepoRevisionAndPathParams(r *http.Request) (*repo.Repository, repo.Revision, string, error) { repository, revision, err := db.readRepoAndRevisionParams(r) if err != nil { return nil, repo.Revision(""), "", err } fileName, err := url.QueryUnescape(r.URL.Query().Get("fileName")) if err != nil || fileName == "" { return nil, repo.Revision(""), "", errors.New("Missing the fileName parameter") } err = (*repository).ValidatePathAtRevision(revision, fileName) return repository, revision, fileName, err }
func (db Dashboard) readRepoAndRevisionParams(r *http.Request) (*repo.Repository, repo.Revision, error) { repository, err := db.readRepoParam(r) if err != nil { return nil, repo.Revision(""), err } revisionParam := r.URL.Query().Get("revision") if revisionParam == "" { return nil, repo.Revision(""), errors.New("Missing the revision parameter") } revision, err := (*repository).ValidateRevision(revisionParam) if err != nil { return nil, repo.Revision(""), err } return repository, revision, nil }
func (db Dashboard) readRepoRevisionPathAndLineNumberParams(r *http.Request) (*repo.Repository, repo.Revision, string, int, error) { repository, revision, fileName, err := db.readRepoRevisionAndPathParams(r) if err != nil { return nil, repo.Revision(""), "", 0, err } lineNumberParam := r.URL.Query().Get("lineNumber") if lineNumberParam == "" { return nil, repo.Revision(""), "", 0, errors.New("Missing the lineNumber param") } lineNumber, err := strconv.Atoi(lineNumberParam) if err != nil { return nil, repo.Revision(""), "", 0, fmt.Errorf("Invalid format for the lineNumber parameter: %v", err) } err = (*repository).ValidateLineNumberInPathAtRevision(revision, fileName, lineNumber) return repository, revision, fileName, lineNumber, err }
func init() { mockAlias = repo.Alias{"branch", repo.Revision("revision")} mockTodo = repo.Line{ Revision: repo.Revision(TestRevision), FileName: TestFileName, LineNumber: TestLineNumber, Contents: TestTodoContents, } aliases := make([]repo.Alias, 0) aliases = append(aliases, mockAlias) revisionTodos := make(map[string][]repo.Line) revisionTodos[TestRevision] = append(revisionTodos[TestRevision], mockTodo) mockRepo = repotest.MockRepository{ Aliases: aliases, RevisionTodos: revisionTodos, } mockRepos = make(map[string]*repo.Repository) mockRepos[mockRepo.GetRepoId()] = &mockRepo }
func (repository MockRepository) ValidateRevision(revisionString string) (repo.Revision, error) { if _, ok := repository.RevisionTodos[revisionString]; ok { return repo.Revision(revisionString), nil } return repo.Revision(""), errors.New(fmt.Sprintf("Not a valid revision: %s", revisionString)) }