@@ -90,6 +90,7 @@ type Service interface {
9090 SignedIndividualCallbackGitlab (ctx context.Context , payload []byte , userID , organizationID , repositoryID , mergeRequestID string ) error
9191 SignedIndividualCallbackGerrit (ctx context.Context , payload []byte , userID string ) error
9292 SignedCorporateCallback (ctx context.Context , payload []byte , companyID , projectID string ) error
93+ GetUserActiveSignature (ctx context.Context , userID string ) (* models.UserActiveSignature , error )
9394}
9495
9596// service
@@ -2769,3 +2770,52 @@ func claSignatoryEmailContent(params ClaSignatoryEmailParams) (string, string) {
27692770
27702771 return emailSubject , emailBody
27712772}
2773+
2774+ func (s * service ) GetUserActiveSignature (ctx context.Context , userID string ) (* models.UserActiveSignature , error ) {
2775+ f := logrus.Fields {
2776+ "functionName" : "sign.GetUserActiveSignature" ,
2777+ utils .XREQUESTID : ctx .Value (utils .XREQUESTID ),
2778+ "userID" : userID ,
2779+ }
2780+ activeSignatureMetadata , err := s .storeRepository .GetActiveSignatureMetaData (ctx , userID )
2781+ if err != nil {
2782+ log .WithFields (f ).WithError (err ).Warnf ("unable to get active signature meta data for user: %s" , userID )
2783+ return nil , err
2784+ }
2785+
2786+ log .WithFields (f ).Debugf ("active signature metadata: %+v" , activeSignatureMetadata )
2787+ isGitlab := false
2788+ var mergeRequestId * string
2789+ if mrId , ok := activeSignatureMetadata ["merge_request_id" ].(string ); ok {
2790+ isGitlab = true
2791+ mergeRequestId = & mrId
2792+ }
2793+ log .WithFields (f ).Debugf ("generating signature callback url gitlab=%v..." , isGitlab )
2794+
2795+ var callBackURL string
2796+ if isGitlab {
2797+ callBackURL , err = s .getIndividualSignatureCallbackURLGitlab (ctx , userID , activeSignatureMetadata )
2798+ if err != nil {
2799+ log .WithFields (f ).WithError (err ).Warnf ("unable to get gitlab signature callback url for user: %s" , userID )
2800+ return nil , err
2801+ }
2802+ } else {
2803+ callBackURL , err = s .getIndividualSignatureCallbackURL (ctx , userID , activeSignatureMetadata )
2804+ if err != nil {
2805+ log .WithFields (f ).WithError (err ).Warnf ("unable to get github signature callback url for user: %s" , userID )
2806+ return nil , err
2807+ }
2808+ }
2809+ log .WithFields (f ).Debugf ("signature callback url: %s" , callBackURL )
2810+ projectId , _ := activeSignatureMetadata ["project_id" ].(string )
2811+ pullRequestId , _ := activeSignatureMetadata ["pull_request_id" ].(string )
2812+ repositoryId , _ := activeSignatureMetadata ["repository_id" ].(string )
2813+ return & models.UserActiveSignature {
2814+ MergeRequestID : mergeRequestId ,
2815+ ProjectID : projectId ,
2816+ PullRequestID : pullRequestId ,
2817+ RepositoryID : repositoryId ,
2818+ ReturnURL : strfmt .URI (callBackURL ),
2819+ UserID : userID ,
2820+ }, nil
2821+ }
0 commit comments