Skip to content

Commit dae876b

Browse files
Cleanup
Signed-off-by: Lukasz Gryglicki <lgryglicki@cncf.io> Assisted by [OpenAI](https://platform.openai.com/) Assisted by [GitHub Copilot](https://github.com/features/copilot)
1 parent ff8366a commit dae876b

1 file changed

Lines changed: 0 additions & 82 deletions

File tree

cla-backend-legacy/internal/api/handlers.go

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -9351,81 +9351,6 @@ func (h *Handlers) PostCorporateSignedV2(w http.ResponseWriter, r *http.Request)
93519351
// Python: cla/routes.py:1950 get_return_url()
93529352
// Calls: cla.controllers.signing.return_url
93539353

9354-
var githubSignedIndividualCallbackPathRE = regexp.MustCompile(`/v[0-9]+/signed/individual/([^/?#]+)/([^/?#]+)/([^/?#]+)`) // installation, repository, PR
9355-
9356-
func githubSignedIndividualCallbackParams(sig map[string]types.AttributeValue) (installationID, repositoryID, pullRequestID string, ok bool) {
9357-
callbackURL := strings.TrimSpace(getAttrString(sig, "signature_callback_url"))
9358-
if callbackURL == "" {
9359-
return "", "", "", false
9360-
}
9361-
if u, err := url.Parse(callbackURL); err == nil && strings.TrimSpace(u.Path) != "" {
9362-
callbackURL = u.Path
9363-
}
9364-
matches := githubSignedIndividualCallbackPathRE.FindStringSubmatch(callbackURL)
9365-
if len(matches) != 4 {
9366-
return "", "", "", false
9367-
}
9368-
installationID = strings.TrimSpace(matches[1])
9369-
repositoryID = strings.TrimSpace(matches[2])
9370-
pullRequestID = strings.TrimSpace(matches[3])
9371-
if installationID == "" || repositoryID == "" || pullRequestID == "" {
9372-
return "", "", "", false
9373-
}
9374-
return installationID, repositoryID, pullRequestID, true
9375-
}
9376-
9377-
func isGitHubIndividualSignature(sig map[string]types.AttributeValue) bool {
9378-
if sig == nil {
9379-
return false
9380-
}
9381-
if !strings.EqualFold(strings.TrimSpace(getAttrString(sig, "signature_reference_type")), "user") {
9382-
return false
9383-
}
9384-
if strings.EqualFold(strings.TrimSpace(getAttrString(sig, "signature_return_url_type")), "github") {
9385-
return true
9386-
}
9387-
return strings.Contains(strings.ToLower(getAttrString(sig, "signature_callback_url")), "/signed/individual/") && strings.Contains(strings.ToLower(getAttrString(sig, "signature_return_url")), "github.com/")
9388-
}
9389-
9390-
func (h *Handlers) refreshGitHubChangeRequestBeforeReturn(ctx context.Context, signatureID string, sig map[string]types.AttributeValue) {
9391-
if h == nil || h.signatures == nil || !isGitHubIndividualSignature(sig) {
9392-
return
9393-
}
9394-
9395-
currentSig := sig
9396-
const attempts = 10
9397-
for attempt := 1; attempt <= attempts && !getAttrBool(currentSig, "signature_signed"); attempt++ {
9398-
if attempt > 1 {
9399-
time.Sleep(500 * time.Millisecond)
9400-
}
9401-
refreshed, found, err := h.signatures.GetByID(ctx, signatureID)
9402-
if err != nil {
9403-
logging.Warnf("return_url - unable to refresh signature before GitHub status update (signature_id=%s): %v", signatureID, err)
9404-
return
9405-
}
9406-
if found {
9407-
currentSig = refreshed
9408-
}
9409-
}
9410-
9411-
if !getAttrBool(currentSig, "signature_signed") {
9412-
logging.Warnf("return_url - GitHub signature still not marked signed before redirect (signature_id=%s); skipping status refresh", signatureID)
9413-
return
9414-
}
9415-
9416-
installationID, repositoryID, pullRequestID, ok := githubSignedIndividualCallbackParams(currentSig)
9417-
if !ok {
9418-
logging.Warnf("return_url - unable to derive GitHub callback metadata before redirect (signature_id=%s)", signatureID)
9419-
return
9420-
}
9421-
9422-
if err := h.triggerGitHubChangeRequestUpdateV4(ctx, installationID, repositoryID, pullRequestID); err != nil {
9423-
logging.Warnf("return_url - GitHub status refresh failed before redirect (signature_id=%s, installation_id=%s, repository_id=%s, pull_request_id=%s): %v", signatureID, installationID, repositoryID, pullRequestID, err)
9424-
return
9425-
}
9426-
logging.Infof("return_url - refreshed GitHub status before redirect (signature_id=%s, repository_id=%s, pull_request_id=%s)", signatureID, repositoryID, pullRequestID)
9427-
}
9428-
94299354
var canceledSignatureHTML = template.Must(template.New("canceledSignature").Parse(`
94309355
<html lang="en">
94319356
<head>
@@ -9538,13 +9463,6 @@ func (h *Handlers) GetReturnUrlV2(w http.ResponseWriter, r *http.Request) {
95389463
}
95399464

95409465
if returnURL := getAttrString(sig, "signature_return_url"); returnURL != "" {
9541-
// h.refreshGitHubChangeRequestBeforeReturn(ctx, signatureID, sig)
9542-
// Legacy Python (cla/controllers/signing.py::return_url) has an eventual-consistency wait loop
9543-
// for v2 company signatures: it checks that all CLA managers listed in signature_acl have
9544-
// the "cla-manager" role assigned (via platform org service scopes) before redirecting.
9545-
//
9546-
// This does not change the final behavior (it always redirects), but it avoids redirecting
9547-
// too early in cases where the UI expects the role assignment to be visible immediately.
95489466
projectID := getAttrString(sig, "signature_project_id")
95499467
refType := strings.ToLower(strings.TrimSpace(getAttrString(sig, "signature_reference_type")))
95509468
if projectID != "" && refType == "company" && h.projects != nil && h.companies != nil && h.userService != nil && h.projectCLAGroups != nil {

0 commit comments

Comments
 (0)