mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 14:35:40 +00:00
adjust to ugly linting
This commit is contained in:
parent
1e40b814a1
commit
e704e5adcc
|
@ -18,7 +18,7 @@ type Validateables interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActorID struct {
|
type ActorID struct {
|
||||||
Id string
|
ID string
|
||||||
Source string
|
Source string
|
||||||
Schema string
|
Schema string
|
||||||
Path string
|
Path string
|
||||||
|
@ -46,7 +46,7 @@ func newActorID(validatedURI *url.URL, source string) (ActorID, error) {
|
||||||
id := pathWithActorID[length-1]
|
id := pathWithActorID[length-1]
|
||||||
|
|
||||||
result := ActorID{}
|
result := ActorID{}
|
||||||
result.Id = id
|
result.ID = id
|
||||||
result.Source = source
|
result.Source = source
|
||||||
result.Schema = validatedURI.Scheme
|
result.Schema = validatedURI.Scheme
|
||||||
result.Host = validatedURI.Hostname()
|
result.Host = validatedURI.Hostname()
|
||||||
|
@ -86,7 +86,6 @@ func NewPersonID(uri string, source string) (PersonID, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRepositoryID(uri string, source string) (RepositoryID, error) {
|
func NewRepositoryID(uri string, source string) (RepositoryID, error) {
|
||||||
|
|
||||||
if !validation.IsAPIURL(uri) {
|
if !validation.IsAPIURL(uri) {
|
||||||
return RepositoryID{}, fmt.Errorf("uri %s is not a valid repo url on this host %s", uri, setting.AppURL+"api")
|
return RepositoryID{}, fmt.Errorf("uri %s is not a valid repo url on this host %s", uri, setting.AppURL+"api")
|
||||||
}
|
}
|
||||||
|
@ -113,20 +112,20 @@ func NewRepositoryID(uri string, source string) (RepositoryID, error) {
|
||||||
func (id ActorID) AsURI() string {
|
func (id ActorID) AsURI() string {
|
||||||
var result string
|
var result string
|
||||||
if id.Port == "" {
|
if id.Port == "" {
|
||||||
result = fmt.Sprintf("%s://%s/%s/%s", id.Schema, id.Host, id.Path, id.Id)
|
result = fmt.Sprintf("%s://%s/%s/%s", id.Schema, id.Host, id.Path, id.ID)
|
||||||
} else {
|
} else {
|
||||||
result = fmt.Sprintf("%s://%s:%s/%s/%s", id.Schema, id.Host, id.Port, id.Path, id.Id)
|
result = fmt.Sprintf("%s://%s:%s/%s/%s", id.Schema, id.Host, id.Port, id.Path, id.ID)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (id PersonID) AsWebfinger() string {
|
func (id PersonID) AsWebfinger() string {
|
||||||
result := fmt.Sprintf("@%s@%s", strings.ToLower(id.Id), strings.ToLower(id.Host))
|
result := fmt.Sprintf("@%s@%s", strings.ToLower(id.ID), strings.ToLower(id.Host))
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func (id PersonID) AsLoginName() string {
|
func (id PersonID) AsLoginName() string {
|
||||||
result := fmt.Sprintf("%s%s", strings.ToLower(id.Id), id.HostSuffix())
|
result := fmt.Sprintf("%s%s", strings.ToLower(id.ID), id.HostSuffix())
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +137,7 @@ func (id PersonID) HostSuffix() string {
|
||||||
// Validate collects error strings in a slice and returns this
|
// Validate collects error strings in a slice and returns this
|
||||||
func (id ActorID) Validate() []string {
|
func (id ActorID) Validate() []string {
|
||||||
var result []string
|
var result []string
|
||||||
result = append(result, validation.ValidateNotEmpty(id.Id, "userId")...)
|
result = append(result, validation.ValidateNotEmpty(id.ID, "userId")...)
|
||||||
result = append(result, validation.ValidateNotEmpty(id.Source, "source")...)
|
result = append(result, validation.ValidateNotEmpty(id.Source, "source")...)
|
||||||
result = append(result, validation.ValidateNotEmpty(id.Schema, "schema")...)
|
result = append(result, validation.ValidateNotEmpty(id.Schema, "schema")...)
|
||||||
result = append(result, validation.ValidateNotEmpty(id.Path, "path")...)
|
result = append(result, validation.ValidateNotEmpty(id.Path, "path")...)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
func TestNewPersonId(t *testing.T) {
|
func TestNewPersonId(t *testing.T) {
|
||||||
expected := PersonID{}
|
expected := PersonID{}
|
||||||
expected.Id = "1"
|
expected.ID = "1"
|
||||||
expected.Source = "forgejo"
|
expected.Source = "forgejo"
|
||||||
expected.Schema = "https"
|
expected.Schema = "https"
|
||||||
expected.Path = "api/v1/activitypub/user-id"
|
expected.Path = "api/v1/activitypub/user-id"
|
||||||
|
@ -24,7 +24,7 @@ func TestNewPersonId(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
expected = PersonID{}
|
expected = PersonID{}
|
||||||
expected.Id = "1"
|
expected.ID = "1"
|
||||||
expected.Source = "forgejo"
|
expected.Source = "forgejo"
|
||||||
expected.Schema = "https"
|
expected.Schema = "https"
|
||||||
expected.Path = "api/v1/activitypub/user-id"
|
expected.Path = "api/v1/activitypub/user-id"
|
||||||
|
@ -40,7 +40,7 @@ func TestNewPersonId(t *testing.T) {
|
||||||
func TestNewRepositoryId(t *testing.T) {
|
func TestNewRepositoryId(t *testing.T) {
|
||||||
setting.AppURL = "http://localhost:3000/"
|
setting.AppURL = "http://localhost:3000/"
|
||||||
expected := RepositoryID{}
|
expected := RepositoryID{}
|
||||||
expected.Id = "1"
|
expected.ID = "1"
|
||||||
expected.Source = "forgejo"
|
expected.Source = "forgejo"
|
||||||
expected.Schema = "http"
|
expected.Schema = "http"
|
||||||
expected.Path = "api/activitypub/repository-id"
|
expected.Path = "api/activitypub/repository-id"
|
||||||
|
@ -66,7 +66,7 @@ func TestActorIdValidation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sut = ActorID{}
|
sut = ActorID{}
|
||||||
sut.Id = "1"
|
sut.ID = "1"
|
||||||
sut.Source = "forgejox"
|
sut.Source = "forgejox"
|
||||||
sut.Schema = "https"
|
sut.Schema = "https"
|
||||||
sut.Path = "api/v1/activitypub/user-id"
|
sut.Path = "api/v1/activitypub/user-id"
|
||||||
|
@ -78,7 +78,7 @@ func TestActorIdValidation(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
sut = ActorID{}
|
sut = ActorID{}
|
||||||
sut.Id = "1"
|
sut.ID = "1"
|
||||||
sut.Source = "forgejo"
|
sut.Source = "forgejo"
|
||||||
sut.Schema = "https"
|
sut.Schema = "https"
|
||||||
sut.Path = "api/v1/activitypub/user-id"
|
sut.Path = "api/v1/activitypub/user-id"
|
||||||
|
@ -92,7 +92,7 @@ func TestActorIdValidation(t *testing.T) {
|
||||||
|
|
||||||
func TestPersonIdValidation(t *testing.T) {
|
func TestPersonIdValidation(t *testing.T) {
|
||||||
sut := PersonID{}
|
sut := PersonID{}
|
||||||
sut.Id = "1"
|
sut.ID = "1"
|
||||||
sut.Source = "forgejo"
|
sut.Source = "forgejo"
|
||||||
sut.Schema = "https"
|
sut.Schema = "https"
|
||||||
sut.Path = "path"
|
sut.Path = "path"
|
||||||
|
|
|
@ -102,7 +102,7 @@ func RepositoryInbox(ctx *context.APIContext) {
|
||||||
ctx.ServerError("Validate objectId", err)
|
ctx.ServerError("Validate objectId", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if objectID.Id != fmt.Sprint(repository.ID) {
|
if objectID.ID != fmt.Sprint(repository.ID) {
|
||||||
ctx.ServerError("Validate objectId", err)
|
ctx.ServerError("Validate objectId", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ func createUserFromAP(ctx *context.APIContext, personID forgefed.PersonID) (*use
|
||||||
|
|
||||||
// validate response; ToDo: Should we widen the restrictions here?
|
// validate response; ToDo: Should we widen the restrictions here?
|
||||||
if response.StatusCode != 200 {
|
if response.StatusCode != 200 {
|
||||||
err = fmt.Errorf("got non 200 status code for id: %v", personID.Id)
|
err = fmt.Errorf("got non 200 status code for id: %v", personID.ID)
|
||||||
return &user_model.User{}, err
|
return &user_model.User{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue