mirror of
https://lab.forgefriends.org/friendlyforgeformat/gof3.git
synced 2025-10-06 08:02:46 +02:00
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
// Copyright Earl Warren <contact@earl-warren.org>
|
|
// Copyright Loïc Dachary <loic@dachary.org>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package f3
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"lab.forgefriends.org/friendlyforgeformat/gof3/tree/generic"
|
|
)
|
|
|
|
type Path interface {
|
|
generic.Path
|
|
Root() Path
|
|
Forge() Path
|
|
Assets() Path
|
|
Comments() Path
|
|
Issues() Path
|
|
Labels() Path
|
|
Milestones() Path
|
|
Organizations() Path
|
|
Projects() Path
|
|
PullRequests() Path
|
|
Reactions() Path
|
|
Releases() Path
|
|
Repositories() Path
|
|
Reviews() Path
|
|
ReviewComments() Path
|
|
Topics() Path
|
|
Users() Path
|
|
}
|
|
|
|
type path struct {
|
|
generic.PathImplementation
|
|
}
|
|
|
|
func (o path) popKind(kind generic.Kind) Path {
|
|
if string(o.First().GetID()) != string(kind) {
|
|
panic(fmt.Errorf("%s expected %s got %s", o, kind, o.First().GetID()))
|
|
}
|
|
return ToPath(o.RemoveFirst())
|
|
}
|
|
|
|
func (o path) Root() Path { return o.popKind(generic.Kind("")) }
|
|
func (o path) Forge() Path { return o.popKind(KindForge) }
|
|
func (o path) Assets() Path { return o.popKind(KindAssets) }
|
|
func (o path) Comments() Path { return o.popKind(KindComments) }
|
|
func (o path) Issues() Path { return o.popKind(KindIssues) }
|
|
func (o path) Labels() Path { return o.popKind(KindLabels) }
|
|
func (o path) Milestones() Path { return o.popKind(KindMilestones) }
|
|
func (o path) Organizations() Path { return o.popKind(KindOrganizations) }
|
|
func (o path) Projects() Path { return o.popKind(KindProjects) }
|
|
func (o path) PullRequests() Path { return o.popKind(KindPullRequests) }
|
|
func (o path) Reactions() Path { return o.popKind(KindReactions) }
|
|
func (o path) Releases() Path { return o.popKind(KindReleases) }
|
|
func (o path) Repositories() Path { return o.popKind(KindRepositories) }
|
|
func (o path) Reviews() Path { return o.popKind(KindReviews) }
|
|
func (o path) ReviewComments() Path { return o.popKind(KindReviewComments) }
|
|
func (o path) Topics() Path { return o.popKind(KindTopics) }
|
|
func (o path) Users() Path { return o.popKind(KindUsers) }
|
|
|
|
func ToPath(other generic.Path) Path {
|
|
return path{other.(generic.PathImplementation)}
|
|
}
|
|
|
|
func NewPathFromString(pathString string) Path {
|
|
return ToPath(generic.NewPathFromString(pathString))
|
|
}
|
|
|
|
func NewPath(nodes ...generic.NodeInterface) Path {
|
|
return path{
|
|
PathImplementation: generic.PathImplementation(nodes),
|
|
}
|
|
}
|