mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-21 18:17:45 +02:00
Merge remote-tracking branch 'upstream/main' into limit-repo-size
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
package structs
|
||||
|
||||
// CommitStatusState holds the state of a CommitStatus
|
||||
// It can be "pending", "success", "error", "failure", and "warning"
|
||||
// It can be "pending", "success", "error" and "failure"
|
||||
type CommitStatusState string
|
||||
|
||||
const (
|
||||
@@ -18,14 +18,25 @@ const (
|
||||
CommitStatusFailure CommitStatusState = "failure"
|
||||
)
|
||||
|
||||
var commitStatusPriorities = map[CommitStatusState]int{
|
||||
CommitStatusError: 0,
|
||||
CommitStatusFailure: 1,
|
||||
CommitStatusPending: 2,
|
||||
CommitStatusSuccess: 3,
|
||||
}
|
||||
|
||||
// NoBetterThan returns true if this State is no better than the given State
|
||||
// This function only handles the states defined in CommitStatusPriorities
|
||||
func (css CommitStatusState) NoBetterThan(css2 CommitStatusState) bool {
|
||||
commitStatusPriorities := map[CommitStatusState]int{
|
||||
CommitStatusError: 0,
|
||||
CommitStatusFailure: 1,
|
||||
CommitStatusPending: 2,
|
||||
CommitStatusSuccess: 3,
|
||||
// NoBetterThan only handles the 4 states above
|
||||
if _, exist := commitStatusPriorities[css]; !exist {
|
||||
return false
|
||||
}
|
||||
|
||||
if _, exist := commitStatusPriorities[css2]; !exist {
|
||||
return false
|
||||
}
|
||||
|
||||
return commitStatusPriorities[css] <= commitStatusPriorities[css2]
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
// Copyright 2023 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package structs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNoBetterThan(t *testing.T) {
|
||||
type args struct {
|
||||
css CommitStatusState
|
||||
css2 CommitStatusState
|
||||
}
|
||||
var unExpectedState CommitStatusState
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "success is no better than success",
|
||||
args: args{
|
||||
css: CommitStatusSuccess,
|
||||
css2: CommitStatusSuccess,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "success is no better than pending",
|
||||
args: args{
|
||||
css: CommitStatusSuccess,
|
||||
css2: CommitStatusPending,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "success is no better than failure",
|
||||
args: args{
|
||||
css: CommitStatusSuccess,
|
||||
css2: CommitStatusFailure,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "success is no better than error",
|
||||
args: args{
|
||||
css: CommitStatusSuccess,
|
||||
css2: CommitStatusError,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "pending is no better than success",
|
||||
args: args{
|
||||
css: CommitStatusPending,
|
||||
css2: CommitStatusSuccess,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "pending is no better than pending",
|
||||
args: args{
|
||||
css: CommitStatusPending,
|
||||
css2: CommitStatusPending,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "pending is no better than failure",
|
||||
args: args{
|
||||
css: CommitStatusPending,
|
||||
css2: CommitStatusFailure,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "pending is no better than error",
|
||||
args: args{
|
||||
css: CommitStatusPending,
|
||||
css2: CommitStatusError,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "failure is no better than success",
|
||||
args: args{
|
||||
css: CommitStatusFailure,
|
||||
css2: CommitStatusSuccess,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "failure is no better than pending",
|
||||
args: args{
|
||||
css: CommitStatusFailure,
|
||||
css2: CommitStatusPending,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "failure is no better than failure",
|
||||
args: args{
|
||||
css: CommitStatusFailure,
|
||||
css2: CommitStatusFailure,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "failure is no better than error",
|
||||
args: args{
|
||||
css: CommitStatusFailure,
|
||||
css2: CommitStatusError,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "error is no better than success",
|
||||
args: args{
|
||||
css: CommitStatusError,
|
||||
css2: CommitStatusSuccess,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "error is no better than pending",
|
||||
args: args{
|
||||
css: CommitStatusError,
|
||||
css2: CommitStatusPending,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "error is no better than failure",
|
||||
args: args{
|
||||
css: CommitStatusError,
|
||||
css2: CommitStatusFailure,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "error is no better than error",
|
||||
args: args{
|
||||
css: CommitStatusError,
|
||||
css2: CommitStatusError,
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "unExpectedState is no better than success",
|
||||
args: args{
|
||||
css: unExpectedState,
|
||||
css2: CommitStatusSuccess,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "unExpectedState is no better than unExpectedState",
|
||||
args: args{
|
||||
css: unExpectedState,
|
||||
css2: unExpectedState,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := tt.args.css.NoBetterThan(tt.args.css2)
|
||||
if result != tt.want {
|
||||
t.Errorf("NoBetterThan() = %v, want %v", result, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ type Organization struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
FullName string `json:"full_name"`
|
||||
Email string `json:"email"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
Description string `json:"description"`
|
||||
Website string `json:"website"`
|
||||
@@ -32,6 +33,7 @@ type CreateOrgOption struct {
|
||||
// required: true
|
||||
UserName string `json:"username" binding:"Required;Username;MaxSize(40)"`
|
||||
FullName string `json:"full_name" binding:"MaxSize(100)"`
|
||||
Email string `json:"email" binding:"MaxSize(255)"`
|
||||
Description string `json:"description" binding:"MaxSize(255)"`
|
||||
Website string `json:"website" binding:"ValidUrl;MaxSize(255)"`
|
||||
Location string `json:"location" binding:"MaxSize(50)"`
|
||||
@@ -46,6 +48,7 @@ type CreateOrgOption struct {
|
||||
// EditOrgOption options for editing an organization
|
||||
type EditOrgOption struct {
|
||||
FullName string `json:"full_name" binding:"MaxSize(100)"`
|
||||
Email string `json:"email" binding:"MaxSize(255)"`
|
||||
Description string `json:"description" binding:"MaxSize(255)"`
|
||||
Website string `json:"website" binding:"ValidUrl;MaxSize(255)"`
|
||||
Location string `json:"location" binding:"MaxSize(50)"`
|
||||
|
||||
@@ -29,10 +29,10 @@ type CreateTeamOption struct {
|
||||
IncludesAllRepositories bool `json:"includes_all_repositories"`
|
||||
// enum: read,write,admin
|
||||
Permission string `json:"permission"`
|
||||
// example: ["repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.pulls","repo.releases","repo.projects","repo.ext_wiki"]
|
||||
// example: ["repo.actions","repo.code","repo.issues","repo.ext_issues","repo.wiki","repo.ext_wiki","repo.pulls","repo.releases","repo.projects","repo.ext_wiki"]
|
||||
// Deprecated: This variable should be replaced by UnitsMap and will be dropped in later versions.
|
||||
Units []string `json:"units"`
|
||||
// example: {"repo.code":"read","repo.issues":"write","repo.ext_issues":"none","repo.wiki":"admin","repo.pulls":"owner","repo.releases":"none","repo.projects":"none","repo.ext_wiki":"none"}
|
||||
// example: {"repo.actions","repo.packages","repo.code":"read","repo.issues":"write","repo.ext_issues":"none","repo.wiki":"admin","repo.pulls":"owner","repo.releases":"none","repo.projects":"none","repo.ext_wiki":"none"}
|
||||
UnitsMap map[string]string `json:"units_map"`
|
||||
CanCreateOrgRepo bool `json:"can_create_org_repo"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user