Skip to content

Commit

Permalink
#4 GraphQL-Query for requesting builds
Browse files Browse the repository at this point in the history
  • Loading branch information
BrobotDubstep committed Jun 20, 2020
1 parent 5c993a6 commit 8a5ced8
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/harbourgateway/configuration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func (b BuildConfig) GetEnqueueBuildUrl() string {
return fmt.Sprintf("%s/enqueue", b.Url)
}

func (b BuildConfig) GetRepositoryBuilds() string {
return fmt.Sprintf("%s/builds", b.Url)
}

// NewDefaultOptions returns the default options
func NewDefaultOptions() *Options {
s := Options{
Expand Down
72 changes: 71 additions & 1 deletion pkg/harbourgateway/graphql/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import (
"github.com/graphql-go/graphql"
"github.com/harbourrocks/harbour/pkg/apiclient"
"github.com/harbourrocks/harbour/pkg/auth"
"github.com/harbourrocks/harbour/pkg/harbourbuild/handler"
"github.com/harbourrocks/harbour/pkg/harbourbuild/models"
"github.com/harbourrocks/harbour/pkg/harbourgateway/configuration"
"github.com/harbourrocks/harbour/pkg/harbourgateway/model"
)

var enqueueBuildType = graphql.NewObject(
graphql.ObjectConfig{
Name: "Build",
Name: "EnqueueBuild",
Fields: graphql.Fields{
"buildId": &graphql.Field{
Type: graphql.String,
Expand Down Expand Up @@ -95,3 +96,72 @@ func EnqueueBuildField(options configuration.Options) *graphql.Field {
},
}
}

var buildListType = graphql.NewList(buildType)
var buildType = graphql.NewObject(
graphql.ObjectConfig{
Name: "Build",
Fields: graphql.Fields{
"scmId": &graphql.Field{
Type: graphql.String,
},
"repository": &graphql.Field{
Type: graphql.String,
},
"buildStatus": &graphql.Field{
Type: graphql.String,
},
"tag": &graphql.Field{
Type: graphql.String,
},
"commit": &graphql.Field{
Type: graphql.String,
},
"timestamp": &graphql.Field{
Type: graphql.Int,
},
},
})

func GetBuildsField(options configuration.Options) *graphql.Field {
return &graphql.Field{
Type: buildListType,
Description: "Receive all builds for a repository",
Args: graphql.FieldConfigArgument{
"repository": &graphql.ArgumentConfig{
Type: graphql.String,
Description: "Name of the Docker-Repository",
},
"scmId": &graphql.ArgumentConfig{
Type: graphql.String,
Description: "Id of the SCM-Repository which is the base for the build",
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
oidcTokenStr := auth.GetOidcTokenStrCtx(p.Context)

repository, isOK := p.Args["repository"].(string)
if !isOK {
return nil, errors.New("repository parameter is missing")
}

scmId, isOK := p.Args["scmId"].(string)
if !isOK {
return nil, errors.New("dockerfile parameter is missing")
}

build := &handler.RepositoryBuildsRequest{
Repository: repository,
SCMId: scmId,
}

var response []handler.Build
_, err := apiclient.Post(p.Context, options.BuildConfig.GetRepositoryBuilds(), &response, build, oidcTokenStr, nil)
if err != nil {
return nil, err
}

return response, err
},
}
}
1 change: 1 addition & 0 deletions pkg/harbourgateway/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func RunGatewayServer(o *configuration.Options) error {
"tags": graphql2.TagsField(*o),
"githubOrganizations": graphql2.GithubOrganizationsField(*o),
"githubRepositories": graphql2.GithubRepositoriesField(*o),
"repositoryBuilds": graphql2.GetBuildsField(*o),
},
})

Expand Down

0 comments on commit 8a5ced8

Please sign in to comment.