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

Revert "[#4001]refactor gitlab/github pr auto update" #4129

Merged
merged 1 commit into from
Sep 11, 2023
Merged
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
Revert "[#4001]refactor gitlab/github pr auto update"
This reverts commit 29ad663.

Signed-off-by: Harold Wanyama <hwanyama@contractor.linuxfoundation.org>
  • Loading branch information
nickmango committed Sep 11, 2023
commit c7e7118247c2dd40d3f4c7a6a14e8439732ecebb
4 changes: 2 additions & 2 deletions cla-backend-go/cmd/server.go
Original file line number Diff line number Diff line change
@@ -304,14 +304,14 @@ func server(localMode bool) http.Handler {
v2RepositoriesService := v2Repositories.NewService(gitV1Repository, gitV2Repository, v1ProjectClaGroupRepo, githubOrganizationsRepo, gitlabOrganizationRepo, eventsService)
githubOrganizationsService := github_organizations.NewService(githubOrganizationsRepo, gitV1Repository, v1ProjectClaGroupRepo)
gitlabOrganizationsService := gitlab_organizations.NewService(gitlabOrganizationRepo, v2RepositoriesService, v1ProjectClaGroupRepo, storeRepository, usersService, signaturesRepo, v1CompanyRepo)
gitlabActivityService := gitlab_activity.NewService(gitV1Repository, gitV2Repository, usersRepo, signaturesRepo, v1ProjectClaGroupRepo, v1CompanyRepo, signaturesRepo, gitlabOrganizationsService, storeRepository)
v1SignaturesService := signatures.NewService(signaturesRepo, v1CompanyService, usersService, eventsService, githubOrgValidation, v1RepositoriesService, githubOrganizationsService, gitlabOrganizationsService, v1ProjectService, gitlabApp, configFile.ClaV1ApiURL, configFile.CLALandingPage, configFile.CLALogoURL, gitlabActivityService)
v1SignaturesService := signatures.NewService(signaturesRepo, v1CompanyService, usersService, eventsService, githubOrgValidation, v1RepositoriesService, githubOrganizationsService, v1ProjectService, gitlabApp, configFile.ClaV1ApiURL, configFile.CLALandingPage, configFile.CLALogoURL)
v2SignatureService := v2Signatures.NewService(awsSession, configFile.SignatureFilesBucket, v1ProjectService, v1CompanyService, v1SignaturesService, v1ProjectClaGroupRepo, signaturesRepo, usersService)
v1ClaManagerService := cla_manager.NewService(claManagerReqRepo, v1ProjectClaGroupRepo, v1CompanyService, v1ProjectService, usersService, v1SignaturesService, eventsService, emailTemplateService, configFile.CorporateConsoleV1URL)
v2ClaManagerService := v2ClaManager.NewService(emailTemplateService, v1CompanyService, v1ProjectService, v1ClaManagerService, usersService, v1RepositoriesService, v2CompanyService, eventsService, v1ProjectClaGroupRepo)
v1ApprovalListService := approval_list.NewService(approvalListRepo, v1ProjectClaGroupRepo, v1ProjectService, usersRepo, v1CompanyRepo, v1CLAGroupRepo, signaturesRepo, emailTemplateService, configFile.CorporateConsoleV2URL, http.DefaultClient)
authorizer := auth.NewAuthorizer(authValidator, userRepo)
v2MetricsService := metrics.NewService(metricsRepo, v1ProjectClaGroupRepo)
gitlabActivityService := gitlab_activity.NewService(gitV1Repository, gitV2Repository, usersRepo, signaturesRepo, v1ProjectClaGroupRepo, v1CompanyRepo, signaturesRepo, gitlabOrganizationsService)
gitlabSignService := gitlab_sign.NewService(v2RepositoriesService, usersService, storeRepository, gitlabApp, gitlabOrganizationsService)
v2GithubOrganizationsService := v2GithubOrganizations.NewService(githubOrganizationsRepo, gitV1Repository, v1ProjectClaGroupRepo, githubOrganizationsService)
autoEnableService := dynamo_events.NewAutoEnableService(v1RepositoriesService, gitV1Repository, githubOrganizationsRepo, v1ProjectClaGroupRepo, v1ProjectService)
10 changes: 0 additions & 10 deletions cla-backend-go/signatures/models.go
Original file line number Diff line number Diff line change
@@ -132,13 +132,3 @@ type ActivePullRequest struct {
RepositoryID string `json:"repository_id"`
PullRequestID string `json:"pull_request_id"`
}

// ActiveGitLabPullRequest data model
type ActiveGitLabPullRequest struct {
GitLabAuthorUserName string `json:"gitlab_author_username"`
GitLabAuthorEmail string `json:"gitlab_author_email"`
ClaGroupID string `json:"cla_group_id"`
RepositoryID string `json:"repository_id"`
MergeRequestID string `json:"merge_request_id"`
ProjectID string `json:"project_id"`
}
90 changes: 3 additions & 87 deletions cla-backend-go/signatures/repository.go
Original file line number Diff line number Diff line change
@@ -96,7 +96,6 @@ type SignatureRepository interface {
GetClaGroupCorporateContributors(ctx context.Context, claGroupID string, companyID *string, pageSize *int64, nextKey *string, searchTerm *string) (*models.CorporateContributorList, error)
EclaAutoCreate(ctx context.Context, signatureID string, autoCreateECLA bool) error
ActivateSignature(ctx context.Context, signatureID string) error
GetGitLabActiveMergeRequestMetadata(ctx context.Context, gitLabAuthorUsername, gitLabAuthorEmail string) (*ActiveGitLabPullRequest, error)
}

type iclaSignatureWithDetails struct {
@@ -3036,7 +3035,7 @@ func (repo repository) UpdateApprovalList(ctx context.Context, claManager *model
// Get ICLAs
var wg sync.WaitGroup
wg.Add(len(params.RemoveGitlabUsernameApprovalList))
for _, glUsername := range params.RemoveGitlabUsernameApprovalList {
for _, ghUsername := range params.RemoveGitlabUsernameApprovalList {
go func(gitLabUsername string) {
defer wg.Done()
var iclas []*models.IclaSignature
@@ -3069,7 +3068,7 @@ func (repo repository) UpdateApprovalList(ctx context.Context, claManager *model
if icla != nil {
// Convert to IclSignature instance to leverage invalidateSignatures helper function
approvalList.ICLAs = []*models.IclaSignature{{
GitlabUsername: icla.UserGitlabUsername,
GitlabUsername: icla.UserGHUsername,
LfUsername: icla.UserLFID,
SignatureID: icla.SignatureID,
}}
@@ -3081,7 +3080,7 @@ func (repo repository) UpdateApprovalList(ctx context.Context, claManager *model
// Send Email
repo.sendEmail(ctx, getBestEmail(claUser), &approvalList, iclas, eclas)

}(glUsername)
}(ghUsername)
}
wg.Wait()
}
@@ -4302,86 +4301,3 @@ func decodeNextKey(str string) (map[string]*dynamodb.AttributeValue, error) {

return m, nil
}

// GetGitLabActiveMergeRequestMetadata returns the pull request metadata for the given user ID
func (repo repository) GetGitLabActiveMergeRequestMetadata(ctx context.Context, gitLabAuthorUsername, gitLabAuthorEmail string) (*ActiveGitLabPullRequest, error) {
f := logrus.Fields{
"functionName": "v1.signatures.repository.GetGitLabActiveMergeRequestMetadata",
utils.XREQUESTID: ctx.Value(utils.XREQUESTID),
"gitLabAuthorUsername": gitLabAuthorUsername,
"gitLabAuthorEmail": gitLabAuthorEmail,
}

if gitLabAuthorUsername == "" && gitLabAuthorEmail == "" {
return nil, nil
}

expr, err := expression.NewBuilder().WithProjection(buildSignatureMetadata()).Build()
if err != nil {
log.WithFields(f).WithError(err).Warn("error building expression for user ID query")
return nil, err
}

// Try to lookup based on the following keys - could be indexed by either or both (depends if user shared their
// email and went through the GitHub authorization flow)
var keys []string
if gitLabAuthorUsername != "" {
keys = append(keys, fmt.Sprintf("active_mr:u:%s", gitLabAuthorUsername))
}
if gitLabAuthorEmail != "" {
keys = append(keys, fmt.Sprintf("active_mr:e:%s", gitLabAuthorEmail))
}

var activeSignature ActiveGitLabPullRequest
for _, key := range keys {
itemInput := &dynamodb.GetItemInput{
Key: map[string]*dynamodb.AttributeValue{
"key": {S: aws.String(key)},
},
ExpressionAttributeNames: expr.Names(),
ProjectionExpression: expr.Projection(),
TableName: aws.String(fmt.Sprintf("cla-%s-store", repo.stage)),
}

// Make the DynamoDb Query API call
// log.WithFields(f).Debugf("loading active signature using key: %s", key)
result, queryErr := repo.dynamoDBClient.GetItem(itemInput)
if queryErr != nil {
if queryErr.Error() == dynamodb.ErrCodeResourceNotFoundException {
continue
}
log.WithFields(f).WithError(queryErr).Warnf("error retrieving active signature metadata using key: %s", key)
return nil, queryErr
}

if result == nil || result.Item == nil || result.Item["value"] == nil || result.Item["value"].S == nil {
log.WithFields(f).Debugf("query result is empty for key: %s", key)
continue
}
if result.Item["value"] == nil || result.Item["value"].S == nil {
log.WithFields(f).Debugf("query result value is empty for key: %s", key)
continue
}

// Clean up the JSON string
strValue := utils.StringValue(result.Item["value"].S)
// log.WithFields(f).Debugf("decoding value: %s", strValue)
if strings.HasSuffix(strValue, "\"") {
// Trim the leading and trailing quotes from the JSON record
strValue = strValue[1 : len(strValue)-1]
}
// Unescape the JSON string
strValue = strings.Replace(strValue, "\\\"", "\"", -1)
// log.WithFields(f).Debugf("decoding value: %s", strValue)

jsonUnMarshallErr := json.Unmarshal([]byte(strValue), &activeSignature)
if jsonUnMarshallErr != nil {
log.WithFields(f).WithError(jsonUnMarshallErr).Warn("unable to convert model for active signature ")
return nil, jsonUnMarshallErr
}

return &activeSignature, nil
}

return nil, nil
}
Loading
Loading