refactor(agent-task/capi): drop embedding of unexported struct
Signed-off-by: Babak K. Shandiz <babakks@github.com>
This commit is contained in:
parent
585b639273
commit
19e17c54fd
2 changed files with 107 additions and 84 deletions
|
|
@ -58,8 +58,23 @@ type sessionPullRequest struct {
|
|||
|
||||
// Session is a hydrated in-flight agent task
|
||||
type Session struct {
|
||||
session
|
||||
PullRequest *api.PullRequest `json:"-"`
|
||||
ID string
|
||||
Name string
|
||||
UserID uint64
|
||||
AgentID int64
|
||||
Logs string
|
||||
State string
|
||||
OwnerID uint64
|
||||
RepoID uint64
|
||||
ResourceType string
|
||||
ResourceID int64
|
||||
LastUpdatedAt time.Time
|
||||
CreatedAt time.Time
|
||||
CompletedAt time.Time
|
||||
EventURL string
|
||||
EventType string
|
||||
|
||||
PullRequest *api.PullRequest
|
||||
}
|
||||
|
||||
// ListSessionsForViewer lists all agent sessions for the
|
||||
|
|
@ -235,10 +250,9 @@ func (c *CAPIClient) hydrateSessionPullRequests(sessions []session) ([]*Session,
|
|||
|
||||
newSessions := make([]*Session, 0, len(sessions))
|
||||
for _, s := range sessions {
|
||||
newSessions = append(newSessions, &Session{
|
||||
session: s,
|
||||
PullRequest: prMap[strconv.FormatInt(s.ResourceID, 10)],
|
||||
})
|
||||
newSession := fromAPISession(s)
|
||||
newSession.PullRequest = prMap[strconv.FormatInt(s.ResourceID, 10)]
|
||||
newSessions = append(newSessions, newSession)
|
||||
}
|
||||
|
||||
return newSessions, nil
|
||||
|
|
@ -261,3 +275,23 @@ func generatePullRequestNodeID(repoID, pullRequestID int64) string {
|
|||
|
||||
return "PR_" + encoded
|
||||
}
|
||||
|
||||
func fromAPISession(s session) *Session {
|
||||
return &Session{
|
||||
ID: s.ID,
|
||||
Name: s.Name,
|
||||
UserID: s.UserID,
|
||||
AgentID: s.AgentID,
|
||||
Logs: s.Logs,
|
||||
State: s.State,
|
||||
OwnerID: s.OwnerID,
|
||||
RepoID: s.RepoID,
|
||||
ResourceType: s.ResourceType,
|
||||
ResourceID: s.ResourceID,
|
||||
LastUpdatedAt: s.LastUpdatedAt,
|
||||
CreatedAt: s.CreatedAt,
|
||||
CompletedAt: s.CompletedAt,
|
||||
EventURL: s.EventURL,
|
||||
EventType: s.EventType,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,19 +117,18 @@ func TestListSessionsForViewer(t *testing.T) {
|
|||
},
|
||||
wantOut: []*Session{
|
||||
{
|
||||
session: session{
|
||||
ID: "sess1",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2000,
|
||||
CreatedAt: sampleDate,
|
||||
},
|
||||
|
||||
ID: "sess1",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2000,
|
||||
CreatedAt: sampleDate,
|
||||
PullRequest: &api.PullRequest{
|
||||
ID: "PR_node",
|
||||
FullDatabaseID: "2000",
|
||||
|
|
@ -260,19 +259,17 @@ func TestListSessionsForViewer(t *testing.T) {
|
|||
},
|
||||
wantOut: []*Session{
|
||||
{
|
||||
session: session{
|
||||
ID: "sess1",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2000,
|
||||
CreatedAt: sampleDate,
|
||||
},
|
||||
ID: "sess1",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2000,
|
||||
CreatedAt: sampleDate,
|
||||
PullRequest: &api.PullRequest{
|
||||
ID: "PR_node",
|
||||
FullDatabaseID: "2000",
|
||||
|
|
@ -289,19 +286,17 @@ func TestListSessionsForViewer(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
session: session{
|
||||
ID: "sess2",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2001,
|
||||
CreatedAt: sampleDate,
|
||||
},
|
||||
ID: "sess2",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2001,
|
||||
CreatedAt: sampleDate,
|
||||
PullRequest: &api.PullRequest{
|
||||
ID: "PR_node",
|
||||
FullDatabaseID: "2001",
|
||||
|
|
@ -525,19 +520,17 @@ func TestListSessionsForRepo(t *testing.T) {
|
|||
},
|
||||
wantOut: []*Session{
|
||||
{
|
||||
session: session{
|
||||
ID: "sess1",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2000,
|
||||
CreatedAt: sampleDate,
|
||||
},
|
||||
ID: "sess1",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2000,
|
||||
CreatedAt: sampleDate,
|
||||
PullRequest: &api.PullRequest{
|
||||
ID: "PR_node",
|
||||
FullDatabaseID: "2000",
|
||||
|
|
@ -668,19 +661,17 @@ func TestListSessionsForRepo(t *testing.T) {
|
|||
},
|
||||
wantOut: []*Session{
|
||||
{
|
||||
session: session{
|
||||
ID: "sess1",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2000,
|
||||
CreatedAt: sampleDate,
|
||||
},
|
||||
ID: "sess1",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2000,
|
||||
CreatedAt: sampleDate,
|
||||
PullRequest: &api.PullRequest{
|
||||
ID: "PR_node",
|
||||
FullDatabaseID: "2000",
|
||||
|
|
@ -697,19 +688,17 @@ func TestListSessionsForRepo(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
session: session{
|
||||
ID: "sess2",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2001,
|
||||
CreatedAt: sampleDate,
|
||||
},
|
||||
ID: "sess2",
|
||||
Name: "Build artifacts",
|
||||
UserID: 1,
|
||||
AgentID: 2,
|
||||
Logs: "",
|
||||
State: "completed",
|
||||
OwnerID: 10,
|
||||
RepoID: 1000,
|
||||
ResourceType: "pull",
|
||||
ResourceID: 2001,
|
||||
CreatedAt: sampleDate,
|
||||
PullRequest: &api.PullRequest{
|
||||
ID: "PR_node",
|
||||
FullDatabaseID: "2001",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue