mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
2978 files. The fork is 2026-07-15 (rebrand: gitea.dev -> github.com/hanzoai/git), so 2026 is the year, and "Copyright 2026 Hanzo AI, Inc." was already the form used by the handful of files that had ours. Shape is now: // Copyright 2026 Hanzo AI, Inc. All rights reserved. // Copyright 2015 The Gogs Authors. All rights reserved. // Copyright 2019 The Gitea Authors. All rights reserved. // SPDX-License-Identifier: MIT Ours on top, theirs retained verbatim. Retained because MIT requires it, and separately because they are true — those authors did write that code. Not renamed to "The Git Authors": Git is a different project under a different license, and putting its name here would attribute this code to people who have nothing to do with it. Adding our line is the fix; overwriting theirs would have been both a licence violation and a false statement. gofmt still reports import-order drift in some of these files. It predates this change (verified against a stash) and is left alone rather than burying a one-line-per-file legal change under 3000 files of unrelated reordering. Build clean. Co-authored-by: Hanzo Dev <[email protected]>
65 lines
2.0 KiB
Go
65 lines
2.0 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package convert
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
|
|
git_model "github.com/hanzoai/git/models/git"
|
|
user_model "github.com/hanzoai/git/models/user"
|
|
"github.com/hanzoai/git/modules/commitstatus"
|
|
api "github.com/hanzoai/git/modules/structs"
|
|
)
|
|
|
|
// ToCommitStatus converts git_model.CommitStatus to api.CommitStatus
|
|
func ToCommitStatus(ctx context.Context, status *git_model.CommitStatus) *api.CommitStatus {
|
|
apiStatus := &api.CommitStatus{
|
|
Created: status.CreatedUnix.AsTime(),
|
|
Updated: status.CreatedUnix.AsTime(),
|
|
State: status.State,
|
|
TargetURL: status.TargetURL,
|
|
Description: status.Description,
|
|
ID: status.Index,
|
|
URL: status.APIURL(ctx),
|
|
Context: status.Context,
|
|
}
|
|
|
|
if status.CreatorID != 0 {
|
|
creator, _ := user_model.GetUserByID(ctx, status.CreatorID)
|
|
apiStatus.Creator = ToUser(ctx, creator, nil)
|
|
}
|
|
|
|
return apiStatus
|
|
}
|
|
|
|
func ToCommitStatuses(ctx context.Context, statuses []*git_model.CommitStatus) []*api.CommitStatus {
|
|
apiStatuses := make([]*api.CommitStatus, len(statuses))
|
|
for i, status := range statuses {
|
|
apiStatuses[i] = ToCommitStatus(ctx, status)
|
|
}
|
|
return apiStatuses
|
|
}
|
|
|
|
// ToCombinedStatus converts List of CommitStatus to a CombinedStatus
|
|
func ToCombinedStatus(ctx context.Context, commitID string, statuses []*git_model.CommitStatus, repo *api.Repository) *api.CombinedStatus {
|
|
status := api.CombinedStatus{
|
|
SHA: commitID,
|
|
TotalCount: len(statuses),
|
|
Repository: repo,
|
|
CommitURL: repo.URL + "/commits/" + url.PathEscape(commitID),
|
|
URL: repo.URL + "/commits/" + url.PathEscape(commitID) + "/status",
|
|
}
|
|
|
|
combinedStatus := git_model.CalcCommitStatus(statuses)
|
|
if combinedStatus != nil {
|
|
status.Statuses = ToCommitStatuses(ctx, statuses)
|
|
status.State = combinedStatus.State
|
|
} else {
|
|
status.State = commitstatus.CommitStatusPending
|
|
}
|
|
return &status
|
|
}
|