added pagination to github user sync
This commit is contained in:
@@ -4,14 +4,15 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
gh "github.com/google/go-github/v48/github"
|
gh "github.com/google/go-github/v48/github"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"gitlab.com/texm/shokku/internal/env"
|
"gitlab.com/texm/shokku/internal/env"
|
||||||
"gitlab.com/texm/shokku/internal/models"
|
"gitlab.com/texm/shokku/internal/models"
|
||||||
"gorm.io/gorm/clause"
|
"gorm.io/gorm/clause"
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type githubUser struct {
|
type githubUser struct {
|
||||||
@@ -49,10 +50,26 @@ func SyncUsersToDB(e *env.Env) error {
|
|||||||
for _, install := range installs {
|
for _, install := range installs {
|
||||||
var members []*gh.User
|
var members []*gh.User
|
||||||
var err error
|
var err error
|
||||||
|
var response *gh.Response
|
||||||
|
var options *gh.ListMembersOptions
|
||||||
if install.GetAccount().GetType() == "Organization" {
|
if install.GetAccount().GetType() == "Organization" {
|
||||||
|
var temp_members []*gh.User
|
||||||
|
|
||||||
insClient := client.GetInstallationClient(install.GetID())
|
insClient := client.GetInstallationClient(install.GetID())
|
||||||
org := install.GetAccount().GetLogin()
|
org := install.GetAccount().GetLogin()
|
||||||
members, _, err = insClient.Organizations.ListMembers(ctx, org, nil)
|
temp_members, response, err = insClient.Organizations.ListMembers(ctx, org, options)
|
||||||
|
members = append(members, temp_members...)
|
||||||
|
|
||||||
|
for response.NextPage != 0 {
|
||||||
|
options := &gh.ListMembersOptions{
|
||||||
|
ListOptions: gh.ListOptions{
|
||||||
|
Page: response.NextPage,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
temp_members, response, err = insClient.Organizations.ListMembers(ctx, org, options)
|
||||||
|
members = append(members, temp_members...)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
members = append(members, install.GetAccount())
|
members = append(members, install.GetAccount())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user