dmitri.shuralyov.com/service/change/maintner

Return "not implemented" errors.

Rather than "not found", which is misleading and makes it look like the
implementation isn't working (when in fact there is no implementation).

Simplify some code by indenting the uncommon path.
dmitshur committed 6 years ago commit 1abc7953324d6d9e41b751736ef74726b0891566
Showing partial commit. Full Commit
Collapse all
maintner/maintner.go
@@ -4,11 +4,10 @@ package maintner

import (
	"context"
	"fmt"
	"log"
	"os"
	"sort"
	"strings"

	"github.com/shurcooL/issues"
	"github.com/shurcooL/users"
@@ -99,11 +98,11 @@ func (s service) Count(_ context.Context, rs issues.RepoSpec, opt issues.IssueLi
	return count, nil
}

func (s service) Get(ctx context.Context, _ issues.RepoSpec, id uint64) (issues.Issue, error) {
	// TODO.
	return issues.Issue{}, os.ErrNotExist
	return issues.Issue{}, fmt.Errorf("Get: not implemented")
}

func state(status string) issues.State {
	switch status {
	case "new":
@@ -117,16 +116,16 @@ func state(status string) issues.State {
	}
}

func (s service) ListComments(ctx context.Context, _ issues.RepoSpec, id uint64, opt *issues.ListOptions) ([]issues.Comment, error) {
	// TODO.
	return nil, nil
	return nil, fmt.Errorf("ListComments: not implemented")
}

func (s service) ListEvents(ctx context.Context, _ issues.RepoSpec, id uint64, opt *issues.ListOptions) ([]issues.Event, error) {
	// TODO.
	return nil, nil
	return nil, fmt.Errorf("ListEvents: not implemented")
}

func (s service) CreateComment(_ context.Context, rs issues.RepoSpec, id uint64, c issues.Comment) (issues.Comment, error) {
	// TODO.
	return issues.Comment{}, fmt.Errorf("CreateComment: not implemented")
@@ -159,28 +158,31 @@ func gerritUser(user *maintner.GitPerson) users.User {
		//AvatarURL: fmt.Sprintf("https://%s/accounts/%d/avatar?s=96", s.domain, user.AccountID),
	}
}

func serverProject(rs issues.RepoSpec) (server, project string) {
	if i := strings.IndexByte(rs.URI, '/'); i != -1 {
		return rs.URI[:i], rs.URI[i+1:]
	i := strings.IndexByte(rs.URI, '/')
	if i == -1 {
		return "", ""
	}
	return "", ""
	return rs.URI[:i], rs.URI[i+1:]
}

func server(rs issues.RepoSpec) string {
	if i := strings.IndexByte(rs.URI, '/'); i != -1 {
		return rs.URI[:i]
	i := strings.IndexByte(rs.URI, '/')
	if i == -1 {
		return ""
	}
	return ""
	return rs.URI[:i]
}

func project(rs issues.RepoSpec) string {
	if i := strings.IndexByte(rs.URI, '/'); i != -1 {
		return rs.URI[i+1:]
	i := strings.IndexByte(rs.URI, '/')
	if i == -1 {
		return ""
	}
	return ""
	return rs.URI[i+1:]
}

// firstParagraph returns the first paragraph of text s.
func firstParagraph(s string) string {
	i := strings.Index(s, "\n\n")