@@ -0,0 +1,40 @@
// Package gerrit defines a router for targeting Gerrit subjects.
package gerrit
import (
"context"
"fmt"
"strings"
)
// Router provides HTML URLs of Gerrit subjects.
type Router interface {
// ChangeURL returns the HTML URL of the specified Gerrit change.
// server is the Gerrit server's hostname, such as "go.googlesource.com".
ChangeURL(ctx context.Context, server, project string, changeID uint64) string
// ChangeMessageURL returns the HTML URL of the specified Gerrit change message.
// server is the Gerrit server's hostname, such as "go.googlesource.com".
ChangeMessageURL(ctx context.Context, server, project string, changeID uint64, messageID string) string
}
// GoogleSource provides HTML URLs of Gerrit subjects on googlesource.com.
type GoogleSource struct{}
// ChangeURL returns the HTML URL of the specified Gerrit change on googlesource.com.
func (GoogleSource) ChangeURL(_ context.Context, server, project string, changeID uint64) string {
if !strings.HasSuffix(server, ".googlesource.com") {
return ""
}
sub := server[:len(server)-len(".googlesource.com")]
return fmt.Sprintf("https://%s-review.googlesource.com/c/%s/+/%d", sub, project, changeID)
}
// ChangeMessageURL returns the HTML URL of the specified Gerrit change message on googlesource.com.
func (GoogleSource) ChangeMessageURL(_ context.Context, server, project string, changeID uint64, messageID string) string {
if !strings.HasSuffix(server, ".googlesource.com") {
return ""
}
sub := server[:len(server)-len(".googlesource.com")]
return fmt.Sprintf("https://%s-review.googlesource.com/c/%s/+/%d#message-%s", sub, project, changeID, messageID)
}