Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clangFormat/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dagger.gen.go
/internal/querybuilder/
/querybuilder/
5 changes: 5 additions & 0 deletions clangFormat/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "clangFormat",
"sdk": "go",
"sdkRuntime": "vito/dagger-sdk-go:no-vcs-flag@sha256:0fcc9d2659cdd551acb7aaf25e77215e9687475eb89ec06cae989eaf332ee480"
}
14 changes: 14 additions & 0 deletions clangFormat/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module clang-format

go 1.21.2

require (
github.com/99designs/gqlgen v0.17.31
github.com/Khan/genqlient v0.6.0
golang.org/x/sync v0.3.0
)

require (
github.com/stretchr/testify v1.8.3 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
)
33 changes: 33 additions & 0 deletions clangFormat/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
github.com/99designs/gqlgen v0.17.31 h1:VncSQ82VxieHkea8tz11p7h/zSbvHSxSDZfywqWt158=
github.com/99designs/gqlgen v0.17.31/go.mod h1:i4rEatMrzzu6RXaHydq1nmEPZkb3bKQsnxNRHS4DQB4=
github.com/Khan/genqlient v0.6.0 h1:Bwb1170ekuNIVIwTJEqvO8y7RxBxXu639VJOkKSrwAk=
github.com/Khan/genqlient v0.6.0/go.mod h1:rvChwWVTqXhiapdhLDV4bp9tz/Xvtewwkon4DpWWCRM=
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/vektah/gqlparser/v2 v2.5.6 h1:Ou14T0N1s191eRMZ1gARVqohcbe1e8FrcONScsq8cRU=
github.com/vektah/gqlparser/v2 v2.5.6/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
29 changes: 29 additions & 0 deletions clangFormat/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package main

import (
"context"
)

type ClangFormat struct{}

type CheckFormatOpts struct {
// recursive bool
// ...
}

func (m *ClangFormat) CheckFormat(ctx context.Context, dir *Directory, opts CheckFormatOpts) (*Container, error) {

// get Docker container from hub
c := dag.Container().From("gaetan/clang-tools")

// mount directory into container and make it the working directory
c = c.WithMountedDirectory("/workdir", dir)
c = c.WithWorkdir("/workdir")

// --dry-run: do not apply changes
command := "set -e ; set -o pipefail ; find . -maxdepth 1 -regex '^.*\\.\\(cpp\\|hpp\\|c\\|h\\)$' -print0 | xargs -0 clang-format --dry-run --Werror -style=file"
c = c.WithExec([]string{"ash", "-c", command})
c, err := c.Sync(ctx)

return c, err
}
12 changes: 12 additions & 0 deletions clangFormat/query.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
clangFormat {
checkFormat (
dir: "core.Directory:eyJsbGIiOnsiZGVmIjpbIkd0Z0NDazVpYkc5aU9pOHZjMmhoTWpVMk9tUXlOV1kxWmpGak5UazJPV1JtTWpFeU5qQmpabVptTUdaak5HWmlNelk1WXpCalpqZG1ZbVU1TVRBNE9UTmxOVEEzTURKbU5EVmtabVEwWXpabFkyVVNOQW9TWW5WcGJHUnJhWFF2WTNKbFlYUmxaR0YwRWg0eU1ESXpMVEV3TFRFd1ZERTFPakkwT2pReUxqVTFNVGM1TURBME5sb1NaUW9hWTI5dWRHRnBibVZ5WkM1cGJ5OTFibU52YlhCeVpYTnpaV1FTUjNOb1lUSTFOam94WWpVMk4yUmtNVEkzTVRaa1pUUTRNamRpTXpBM1ptTmpPVFpqWmprMFpHRmpNbVExTkdVM05qTTBZekZoWTJSall6a3lZVGczWVRNeE9HRmhZMll4RWtnS0dXUmhaMmRsY2tKc2IySlRiM1Z5WTJWTlpXUnBZVlI1Y0dVU0syRndjR3hwWTJGMGFXOXVMM1p1WkM1dlkya3VhVzFoWjJVdWJHRjVaWEl1ZGpFdWRHRnlLM3B6ZEdRU0h3b1VaR0ZuWjJWeVFteHZZbE52ZFhKalpWTnBlbVVTQnpjM05qUTJNemxhQUE9PSIsIkNra0tSM05vWVRJMU5qb3hOR1JqTVRjNVpHUmxaakE1WldVMU1XVm1NekkwTW1Sa04ySXlNamsyTkdOa01XRmlPRFEyTlRGa01UVXlZMlZsWWpKbU5EaGpOVGRsTnpaaE1EWTEiXSwibWV0YWRhdGEiOnsic2hhMjU2OjE0MWU1MGUxOGNlOGU2ODVkZmI2ZWYzYzliODk3YTc2OTQ0NjFlMjA1Zjg4ZjgwYTliYjFlY2NlMTA0ZTIwMzYiOnsiY2FwcyI6eyJjb25zdHJhaW50cyI6dHJ1ZSwicGxhdGZvcm0iOnRydWV9fSwic2hhMjU2OjE0ZGMxNzlkZGVmMDllZTUxZWYzMjQyZGQ3YjIyOTY0Y2QxYWI4NDY1MWQxNTJjZWViMmY0OGM1N2U3NmEwNjUiOnsiY2FwcyI6bnVsbH19fSwiZGlyIjoiIiwicGxhdGZvcm0iOnsiYXJjaGl0ZWN0dXJlIjoiYXJtNjQiLCJvcyI6ImxpbnV4In0sInBpcGVsaW5lIjpbXX0="
)
{
stdout
}
}
}

# echo '{host{directory(path: "/Users/gaetan/projects/cubzh/cubzh/core"){id}}}' | dagger query --progress=plain
3 changes: 3 additions & 0 deletions githubStatus/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/dagger.gen.go
/internal/querybuilder/
/querybuilder/
5 changes: 5 additions & 0 deletions githubStatus/dagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "githubStatus",
"sdk": "go",
"sdkRuntime": "vito/dagger-sdk-go:no-vcs-flag@sha256:0fcc9d2659cdd551acb7aaf25e77215e9687475eb89ec06cae989eaf332ee480"
}
14 changes: 14 additions & 0 deletions githubStatus/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github-status

go 1.21.2

require (
github.com/99designs/gqlgen v0.17.31
github.com/Khan/genqlient v0.6.0
golang.org/x/sync v0.3.0
)

require (
github.com/stretchr/testify v1.8.3 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
)
33 changes: 33 additions & 0 deletions githubStatus/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
github.com/99designs/gqlgen v0.17.31 h1:VncSQ82VxieHkea8tz11p7h/zSbvHSxSDZfywqWt158=
github.com/99designs/gqlgen v0.17.31/go.mod h1:i4rEatMrzzu6RXaHydq1nmEPZkb3bKQsnxNRHS4DQB4=
github.com/Khan/genqlient v0.6.0 h1:Bwb1170ekuNIVIwTJEqvO8y7RxBxXu639VJOkKSrwAk=
github.com/Khan/genqlient v0.6.0/go.mod h1:rvChwWVTqXhiapdhLDV4bp9tz/Xvtewwkon4DpWWCRM=
github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/vektah/gqlparser/v2 v2.5.6 h1:Ou14T0N1s191eRMZ1gARVqohcbe1e8FrcONScsq8cRU=
github.com/vektah/gqlparser/v2 v2.5.6/go.mod h1:z8xXUff237NntSuH8mLFijZ+1tjV1swDbpDqjJmk6ME=
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
97 changes: 97 additions & 0 deletions githubStatus/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package main

// echo '{githubStatus{post(accessToken: "foo", state: "pending")}}' | dagger query

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)

const (
statusAPIURL = "https://api.github.com/repos/%s/%s/statuses/%s"
)

type GithubStatus struct{}

type GithubStatusOpts struct {
AccessToken string
Owner string
Repo string
Sha string
State string // error, failure, pending, success
TargetURL string
Description string
Context string // "default" by default
}

type githubStatus struct {
State string `json:"state"`
TargetURL string `json:"target_url,omitempty"`
Description string `json:"description,omitempty"`
Context string `json:"context,omitempty"`
}

type GithubStatusOutput struct {
Success bool `json:"success"`
}

// GithubStatusOutput needs at least one function to become a valid type for GraphQL
func (o *GithubStatusOutput) Banane() {}

func (m *GithubStatus) Post(opts GithubStatusOpts) (*GithubStatusOutput, error) {

url := fmt.Sprintf(statusAPIURL, opts.Owner, opts.Repo, opts.Sha)

status := githubStatus{
State: opts.State,
TargetURL: opts.TargetURL,
Description: opts.Description,
Context: opts.Context,
}

validStates := map[string]bool{
"error": true,
"failure": true,
"pending": true,
"success": true,
}

_, isStateValid := validStates[status.State]
if isStateValid == false {
return &GithubStatusOutput{Success: false}, fmt.Errorf("state (%s) should be error, failure, pending or success", status.State)
}

if status.Context == "" {
status.Context = "default"
}

// Marshal the status into JSON
statusBytes, err := json.Marshal(status)
if err != nil {
return &GithubStatusOutput{Success: false}, fmt.Errorf("unable to marshal status: %w", err)
}

req, err := http.NewRequest("POST", url, bytes.NewBuffer(statusBytes))
if err != nil {
return &GithubStatusOutput{Success: false}, fmt.Errorf("unable to create request: %w", err)
}

req.Header.Set("Authorization", "Bearer "+opts.AccessToken)
req.Header.Set("Accept", "application/vnd.github+json")
req.Header.Set("X-GitHub-Api-Version", "2022-11-28")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return &GithubStatusOutput{Success: false}, fmt.Errorf("failed to make request: %w", err)
}
defer resp.Body.Close()

if resp.StatusCode != http.StatusCreated {
return &GithubStatusOutput{Success: false}, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}

return &GithubStatusOutput{Success: true}, nil
}
12 changes: 12 additions & 0 deletions githubStatus/query.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
githubStatus {
post(
owner: "cubzh"
repo: "cubzh"
sha: "cubzh"
accessToken: "foo"
state: "pending"
description: ""
){ success }
}
}