Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-420] Add feature to support multiple orgs in plugin settings #773

Merged
merged 15 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
[MM-420] Update check org function
  • Loading branch information
ayusht2810 committed May 8, 2024
commit 44ec5382b43f01e4a5d789ba2bc430640f817e18
8 changes: 4 additions & 4 deletions server/plugin/graphql/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type Client struct {
org string
username string
logger pluginapi.LogService
getOrganization func() []string
getOrganizations func() []string
}

// NewClient creates and returns Client. The third party package that queries GraphQL is initialized here.
func NewClient(logger pluginapi.LogService, getOrganization func() []string, token oauth2.Token, username, orgName, enterpriseBaseURL string) *Client {
func NewClient(logger pluginapi.LogService, getOrganizations func() []string, token oauth2.Token, username, orgName, enterpriseBaseURL string) *Client {
ts := oauth2.StaticTokenSource(&token)
httpClient := oauth2.NewClient(context.Background(), ts)
var client Client
Expand All @@ -33,7 +33,7 @@ func NewClient(logger pluginapi.LogService, getOrganization func() []string, tok
client: githubv4.NewClient(httpClient),
logger: logger,
org: orgName,
getOrganization: getOrganization,
getOrganizations: getOrganizations,
}
} else {
baseURL, err := url.Parse(enterpriseBaseURL)
Expand All @@ -49,7 +49,7 @@ func NewClient(logger pluginapi.LogService, getOrganization func() []string, tok
username: username,
org: orgName,
logger: logger,
getOrganization: getOrganization,
getOrganizations: getOrganizations,
}
}

Expand Down
10 changes: 4 additions & 6 deletions server/plugin/graphql/lhs_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ func (c *Client) GetLHSData(ctx context.Context) ([]*github.Issue, []*github.Iss
queryParamOpenPRsCursor: (*githubv4.String)(nil),
}

orgsList := c.getOrganization()
orgsList := c.getOrganizations()

var resultReview, resultAssignee, resultOpenPR []*github.Issue
for _, org := range orgsList {
if org != "" {
params[queryParamOpenPRQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", org, params[queryParamOpenPRQueryArg]))
params[queryParamReviewPRQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", org, params[queryParamReviewPRQueryArg]))
params[queryParamAssigneeQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", org, params[queryParamAssigneeQueryArg]))
}
params[queryParamOpenPRQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", org, params[queryParamOpenPRQueryArg]))
params[queryParamReviewPRQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", org, params[queryParamReviewPRQueryArg]))
params[queryParamAssigneeQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", org, params[queryParamAssigneeQueryArg]))

allReviewRequestsFetched, allAssignmentsFetched, allOpenPRsFetched := false, false, false

Expand Down
7 changes: 3 additions & 4 deletions server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,10 +968,9 @@ func (p *Plugin) HasUnreads(info *GitHubUserInfo) bool {
func (p *Plugin) checkOrg(org string) error {
config := p.getConfiguration()

list := strings.Split(config.GitHubOrg, ",")
for _, configOrg := range list {
configOrg = strings.TrimSpace(strings.ToLower(configOrg))
if configOrg != "" && configOrg == org {
orgList := config.getOrganizations()
for _, configOrg := range orgList {
if configOrg == org {
return nil
}
}
Expand Down
Loading