Skip to content

Commit

Permalink
feat(component,github): add more user and org tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
pinglin committed Dec 31, 2024
1 parent 62e7873 commit 2f6b6d7
Show file tree
Hide file tree
Showing 46 changed files with 5,800 additions and 779 deletions.
25 changes: 13 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ require (
cloud.google.com/go/iam v1.1.10
cloud.google.com/go/longrunning v0.5.9
cloud.google.com/go/storage v1.41.0
code.sajari.com/docconv v1.3.8
github.com/DATA-DOG/go-sqlmock v1.5.2
github.com/JohannesKaufmann/html-to-markdown v1.5.0
github.com/PaesslerAG/jsonpath v0.1.1
github.com/PuerkitoBio/goquery v1.9.1
github.com/anthropics/anthropic-sdk-go v0.2.0-alpha.3
github.com/belong-inc/go-hubspot v0.9.0
github.com/chromedp/chromedp v0.10.0
Expand All @@ -23,16 +25,20 @@ require (
github.com/gabriel-vasile/mimetype v1.4.3
github.com/gage-technologies/mistral-go v1.1.0
github.com/go-audio/audio v1.0.0
github.com/go-audio/wav v1.1.0
github.com/go-chi/chi/v5 v5.1.0
github.com/go-openapi/strfmt v0.23.0
github.com/go-redis/redismock/v9 v9.2.0
github.com/go-resty/resty/v2 v2.12.0
github.com/go-sql-driver/mysql v1.8.1
github.com/gocolly/colly/v2 v2.1.0
github.com/gofrs/uuid v4.4.0+incompatible
github.com/gogo/status v1.1.1
github.com/gojuno/minimock/v3 v3.4.0
github.com/golang-migrate/migrate/v4 v4.15.2
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v62 v62.0.0
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0
github.com/h2non/filetype v1.1.3
Expand All @@ -42,6 +48,7 @@ require (
github.com/instill-ai/usage-client v0.2.4-alpha.0.20240123081026-6c78d9a5197a
github.com/instill-ai/x v0.6.0-alpha
github.com/itchyny/gojq v0.12.14
github.com/jackc/pgconn v1.14.3
github.com/jackc/pgx/v5 v5.5.5
github.com/jmoiron/sqlx v1.4.0
github.com/json-iterator/go v1.1.12
Expand All @@ -53,6 +60,7 @@ require (
github.com/lestrrat-go/option v1.0.0
github.com/lestrrat-go/pdebug v0.0.0-20210111095411-35b07dbf089b
github.com/lestrrat-go/structinfo v0.0.0-20210312050401-7f8bd69d6acb
github.com/lib/pq v1.10.9
github.com/mennanov/fieldmask-utils v1.0.0
github.com/minio/minio-go/v7 v7.0.76
github.com/nakagami/firebirdsql v0.9.10
Expand All @@ -62,13 +70,15 @@ require (
github.com/redis/go-redis/v9 v9.5.1
github.com/sijms/go-ora v1.3.2
github.com/slack-go/slack v0.12.5
github.com/stretchr/testify v1.9.0
github.com/tmc/langchaingo v0.1.10
github.com/u2takey/ffmpeg-go v0.5.0
github.com/warmans/ffmpeg-go v1.0.0
github.com/weaviate/weaviate v1.26.0-rc.1
github.com/weaviate/weaviate-go-client/v4 v4.15.0
github.com/xuri/excelize/v2 v2.8.1
github.com/xwb1989/sqlparser v0.0.0-20180606152119-120387863bf2
github.com/zaf/resample v1.5.0
go.einride.tech/aip v0.60.0
go.mongodb.org/mongo-driver v1.16.0
go.opentelemetry.io/contrib/propagators/b3 v1.17.0
Expand All @@ -83,17 +93,20 @@ require (
go.temporal.io/api v1.16.0
go.temporal.io/sdk v1.21.0
go.uber.org/zap v1.26.0
golang.org/x/crypto v0.31.0
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
golang.org/x/image v0.18.0
golang.org/x/mod v0.17.0
golang.org/x/net v0.33.0
golang.org/x/oauth2 v0.21.0
golang.org/x/text v0.21.0
google.golang.org/api v0.189.0
google.golang.org/genproto/googleapis/api v0.0.0-20240701130421-f6361c86f094
google.golang.org/genproto/googleapis/rpc v0.0.0-20240722135656-d784300faade
google.golang.org/grpc v1.65.0
google.golang.org/protobuf v1.34.2
gopkg.in/guregu/null.v4 v4.0.0
gopkg.in/yaml.v3 v3.0.1
gorm.io/datatypes v1.2.0
gorm.io/driver/postgres v1.5.7
gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde
Expand All @@ -109,7 +122,6 @@ require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/JalfResi/justext v0.0.0-20221106200834-be571e3e3052 // indirect
github.com/PaesslerAG/gval v1.0.0 // indirect
github.com/PuerkitoBio/goquery v1.9.1
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/advancedlogic/GoOse v0.0.0-20191112112754-e742535969c1 // indirect
Expand Down Expand Up @@ -144,7 +156,6 @@ require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gigawattio/window v0.0.0-20180317192513-0f5467e35573 // indirect
github.com/go-audio/riff v1.0.0 // indirect
github.com/go-audio/wav v1.1.0
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand All @@ -156,8 +167,6 @@ require (
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-openapi/validate v0.21.0 // indirect
github.com/go-resty/resty/v2 v2.12.0
github.com/go-sql-driver/mysql v1.8.1
github.com/gobwas/glob v0.2.3 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
Expand All @@ -173,7 +182,6 @@ require (
github.com/google/flatbuffers v23.5.26+incompatible // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.5 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
Expand All @@ -182,7 +190,6 @@ require (
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.14.3
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
Expand All @@ -200,7 +207,6 @@ require (
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/levigross/exp-html v0.0.0-20120902181939-8df60c69a8f5 // indirect
github.com/lib/pq v1.10.9
github.com/machinebox/graphql v0.2.2
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matryer/is v1.4.1 // indirect
Expand Down Expand Up @@ -235,7 +241,6 @@ require (
github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect
github.com/streamer45/silero-vad-go v0.2.1
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.9.0
github.com/temoto/robotstxt v1.1.2 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
Expand All @@ -248,7 +253,6 @@ require (
github.com/xuri/efp v0.0.0-20231025114914-d1ff6096ae53 // indirect
github.com/xuri/nfp v0.0.0-20230919160717-d98342af3f05 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
github.com/zaf/resample v1.5.0
github.com/zeebo/xxh3 v1.0.2 // indirect
gitlab.com/golang-commonmark/html v0.0.0-20191124015941-a22733972181 // indirect
gitlab.com/golang-commonmark/linkify v0.0.0-20191026162114-a0c2df6c8f82 // indirect
Expand All @@ -264,16 +268,13 @@ require (
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.31.0
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240722135656-d784300faade // indirect
gopkg.in/yaml.v3 v3.0.1
gorm.io/driver/mysql v1.4.7 // indirect
modernc.org/mathutil v1.5.0 // indirect
)
60 changes: 11 additions & 49 deletions pkg/component/application/github/v0/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,54 +13,14 @@ import (
"github.com/instill-ai/x/errmsg"
)

// RepositoriesService is a wrapper around the github.RepositoriesService
type RepositoriesService interface {
GetCommit(ctx context.Context, owner string, repository string, sha string, opts *github.ListOptions) (*github.RepositoryCommit, *github.Response, error)
ListHooks(ctx context.Context, owner string, repository string, opts *github.ListOptions) ([]*github.Hook, *github.Response, error)
GetHook(ctx context.Context, owner string, repository string, id int64) (*github.Hook, *github.Response, error)
CreateHook(ctx context.Context, owner string, repository string, hook *github.Hook) (*github.Hook, *github.Response, error)
DeleteHook(ctx context.Context, owner string, repository string, id int64) (*github.Response, error)
EditHook(ctx context.Context, owner string, repository string, id int64, hook *github.Hook) (*github.Hook, *github.Response, error)
}

// RepoInfoInterface is an interface for the RepoInfo struct
type RepoInfoInterface interface {
getOwner() (string, error)
getRepository() (string, error)
}

// RepoInfo is a struct that contains the owner and repository of a repository
type RepoInfo struct {
Owner string `instill:"owner"`
Repository string `instill:"repository"`
}

func (info RepoInfo) getOwner() (string, error) {
if info.Owner == "" {
return "", errmsg.AddMessage(
fmt.Errorf("owner not provided"),
"Owner not provided.",
)
}
return info.Owner, nil
}

func (info RepoInfo) getRepository() (string, error) {
if info.Repository == "" {
return "", errmsg.AddMessage(
fmt.Errorf("repository not provided"),
"Repository not provided.",
)
}
return info.Repository, nil
}

// Client is a struct that contains the github client and the repositories service
type Client struct {
*github.Client
Repositories RepositoriesService
PullRequests PullRequestService
Issues IssuesService
Repositories RepositoriesService
PullRequests PullRequestsService
Issues IssuesService
Users UsersService
Organizations OrganizationsService
}

func newClient(ctx context.Context, setup *structpb.Struct) Client {
Expand All @@ -75,10 +35,12 @@ func newClient(ctx context.Context, setup *structpb.Struct) Client {
}
client := github.NewClient(oauth2Client)
return Client{
Client: client,
Repositories: client.Repositories,
PullRequests: client.PullRequests,
Issues: client.Issues,
Client: client,
Repositories: client.Repositories,
PullRequests: client.PullRequests,
Issues: client.Issues,
Users: client.Users,
Organizations: client.Organizations,
}
}

Expand Down
24 changes: 10 additions & 14 deletions pkg/component/application/github/v0/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,24 @@ func (client *Client) extractCommitFile(file *github.CommitFile) CommitFile {
}
}

func (client *Client) extractCommitInformation(ctx context.Context, owner, repository string, originalCommit *github.RepositoryCommit, needCommitDetails bool) Commit {
func (client *Client) extractCommitInformation(ctx context.Context, owner, repository string, originalCommit *github.RepositoryCommit, needCommitDetails bool) (Commit, error) {
if !needCommitDetails {
return Commit{
SHA: originalCommit.GetSHA(),
Message: originalCommit.GetCommit().GetMessage(),
}
}, nil
}
stats := originalCommit.GetStats()
commitFiles := originalCommit.Files
if stats == nil || commitFiles == nil {
commit, err := client.getCommitFunc(ctx, owner, repository, originalCommit.GetSHA())
if err == nil {
// only update stats and files if there is no error
// otherwise, we will maintain the original commit information
stats = commit.GetStats()
commitFiles = commit.Files
commit, _, err := client.Repositories.GetCommit(ctx, owner, repository, originalCommit.GetSHA(), nil)
if err != nil {
return Commit{}, addErrMsgToClientError(err)
}
// only update stats and files if there is no error
// otherwise, we will maintain the original commit information
stats = commit.GetStats()
commitFiles = commit.Files
}
files := make([]CommitFile, len(commitFiles))
for idx, file := range commitFiles {
Expand All @@ -71,10 +72,5 @@ func (client *Client) extractCommitInformation(ctx context.Context, owner, repos
Changes: stats.GetTotal(),
},
Files: files,
}
}

func (client *Client) getCommitFunc(ctx context.Context, owner string, repository string, sha string) (*github.RepositoryCommit, error) {
commit, _, err := client.Repositories.GetCommit(ctx, owner, repository, sha, nil)
return commit, addErrMsgToClientError(err)
}, nil
}
8 changes: 5 additions & 3 deletions pkg/component/application/github/v0/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ const (
)

var MockGithubClient = &Client{
Repositories: &MockRepositoriesService{},
PullRequests: &MockPullRequestService{},
Issues: &MockIssuesService{},
Repositories: &MockRepositoriesService{},
PullRequests: &MockPullRequestsService{},
Issues: &MockIssuesService{},
Users: &MockUsersService{},
Organizations: &MockOrganizationsService{},
}

type TaskCase[inType any, outType any] struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/component/application/github/v0/config/definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ availableTasks:
- TASK_CREATE_REVIEW_COMMENT
- TASK_LIST_ISSUES
- TASK_GET_ISSUE
- TASK_GET_USER
- TASK_GET_ORGANIZATION
- TASK_CREATE_ISSUE
- TASK_CREATE_WEBHOOK
availableEvents:
Expand Down
Loading

0 comments on commit 2f6b6d7

Please sign in to comment.