FEAT[DXTA-297]: Create workflow for github installation data provisioning#684
Draft
stefanskoricdev wants to merge 9 commits intomainfrom
Draft
FEAT[DXTA-297]: Create workflow for github installation data provisioning#684stefanskoricdev wants to merge 9 commits intomainfrom
stefanskoricdev wants to merge 9 commits intomainfrom
Conversation
7dca458 to
59d6d7d
Compare
59d6d7d to
8bb3f40
Compare
Ante-Koceic
approved these changes
Jul 2, 2025
davidabram
reviewed
Jul 2, 2025
| _, err := temporalClient.ExecuteWorkflow( | ||
| ctx, | ||
| client.StartWorkflowOptions{ | ||
| ID: fmt.Sprintf("onboarding-workflow-%v", time.Now().Format("20060102150405")), |
Member
There was a problem hiding this comment.
I think there should be name of the tenant + org id rather than string + time string.
davidabram
reviewed
Jul 2, 2025
| return data.GetGithubInstallation(installationId, activity.GithubConfig.GithubAppClient, ctx) | ||
| } | ||
|
|
||
| func (activity *DBActivities) SyncGithubInstallationDataToTenant(ctx context.Context, installationId int64, |
davidabram
reviewed
Jul 2, 2025
| amc.allMembers = append(amc.allMembers, ExtendedMember{User: member, Email: Email, Name: Name}) | ||
| } | ||
|
|
||
| func GetInstallationTeamMembersWithEmails(ctx context.Context, members []*github.User, client *github.Client) (ExtendedMembers, error) { |
Member
There was a problem hiding this comment.
I think this code is incredibly complicated, for no good reason.
What I would like to see is to have a potentially single fetch towards github in a single activity, so if something fails you don't need to fetch all the data again.
Here is a better solution.
import (
"context"
"golang.org/x/sync/errgroup"
"github.com/google/go-github/v72/github"
)
type ExtendedMember struct {
User *github.User
Email *string
Name *string
}
func GetInstallationTeamMembersWithEmails(
ctx context.Context,
members []*github.User,
client *github.Client,
) ([]ExtendedMember, error) {
eg, ctx := errgroup.WithContext(ctx)
results := make([]ExtendedMember, len(members))
for i, m := range members {
i, m := i, m
eg.Go(func() error {
user, _, err := client.Users.Get(ctx, *m.Login)
if err != nil {
return err
}
results[i] = ExtendedMember{
User: m,
Email: user.Email,
Name: user.Name,
}
return nil
})
}
if err := eg.Wait(); err != nil {
return nil, err
}
return results, nil
}
davidabram
reviewed
Jul 2, 2025
Comment on lines
+25
to
+40
| for { | ||
| teams, res, err := client.Teams.ListTeams(ctx, installationOrgName, opt) | ||
|
|
||
| if err != nil { | ||
| fmt.Printf("Could not retrieve installation. Error: %v", err.Error()) | ||
| return nil, err | ||
| } | ||
|
|
||
| allTeams = append(allTeams, teams...) | ||
|
|
||
| if res.NextPage == 0 { | ||
| break | ||
| } | ||
|
|
||
| opt.Page = res.NextPage | ||
| } |
Member
There was a problem hiding this comment.
This is incredibly dangerous pattern.
You need to limit max number of pages that you plan to visit.
davidabram
reviewed
Jul 2, 2025
| GithubOrganizationId int64 | ||
| } | ||
|
|
||
| func SyncGithubInstallationDataToTenant( |
Member
There was a problem hiding this comment.
Few cool patterns:
If you re-assign err, you can use:
defer func() {
if err != nil {
_ = tx.Rollback()
}
}()
also error handling can be onelined:
var tenantOrgID int64
const selectTenantOrg = `
SELECT id
FROM organizations
WHERE auth_id = ?`
if err = tx.QueryRowContext(ctx, selectTenantOrg, authID).
Scan(&tenantOrgID); err != nil {
return nil, fmt.Errorf("finding tenant org: %w", err)
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.