@@ -2749,7 +2749,7 @@ def update_pull_request(
27492749 f"{ fn } - Creating new CLA '{ state } ' status - { len (signed )} passed, { missing } failed, "
27502750 f"signing url: { sign_url } "
27512751 )
2752- create_commit_status (commit_obj , state , sign_url , body , context )
2752+ create_commit_status (commit_obj , pull_request , last_commit_sha , state , sign_url , body , context )
27532753 elif signed is not None and len (signed ) > 0 :
27542754 state = "success"
27552755 # For status, we change the context from author_name to 'communitybridge/cla' or the
@@ -2762,7 +2762,7 @@ def update_pull_request(
27622762 f"{ fn } - Creating new CLA '{ state } ' status - { len (signed )} passed, { missing } failed, "
27632763 f"signing url: { sign_url } "
27642764 )
2765- create_commit_status (commit_obj , state , sign_url , body , context )
2765+ create_commit_status (commit_obj , pull_request , last_commit_sha , state , sign_url , body , context )
27662766 else :
27672767 # error condition - should have at least one committer, and they would be in one of the above
27682768 # lists: missing or signed
@@ -2782,7 +2782,7 @@ def update_pull_request(
27822782 f"should have at least one committer in one of these lists: "
27832783 f"{ len (signed )} passed, { missing } "
27842784 )
2785- create_commit_status (commit_obj , state , sign_url , body , context )
2785+ create_commit_status (commit_obj , pull_request , last_commit_sha , state , sign_url , body , context )
27862786
27872787
27882788def create_commit_status_for_merge_group (commit_obj , merge_commit_sha , state , sign_url , body , context ):
@@ -2808,8 +2808,50 @@ def create_commit_status_for_merge_group(commit_obj, merge_commit_sha, state, si
28082808 except Exception as e :
28092809 cla .log .warning (f"Unable to create commit status for " f"and merge commit { merge_commit_sha } : { e } " )
28102810
2811+ def create_commit_status_pr_hash (pull_request , commit_hash , state , sign_url , body , context ):
2812+ """
2813+ Helper function to create a pull request commit status message given the PR and commit hash.
2814+
2815+ :param pull_request: The GitHub Pull Request object.
2816+ :type pull_request: github.PullRequest
2817+ :param commit_hash: The commit hash to post a status on.
2818+ :type commit_hash: string
2819+ :param state: The state of the status.
2820+ :type state: string
2821+ :param sign_url: The link the user will be taken to when clicking on the status message.
2822+ :type sign_url: string
2823+ :param body: The contents of the status message.
2824+ :type body: string
2825+ """
2826+ try :
2827+ commit_obj = None
2828+ for commit in pull_request .get_commits ():
2829+ if commit .sha == commit_hash :
2830+ commit_obj = commit
2831+ break
2832+ if commit_obj is None :
2833+ cla .log .error (
2834+ f"Could not post status { state } on " f"PR: { pull_request .number } , " f"Commit: { commit_hash } not found"
2835+ )
2836+ return
2837+ # context is a string label to differentiate one signer status from another signer status.
2838+ # committer name is used as context label
2839+ cla .log .info (f"Updating status with state '{ state } ' on PR { pull_request .number } for commit { commit_hash } ..." )
2840+ # returns github.CommitStatus.CommitStatus
2841+ resp = commit_obj .create_status (state , sign_url , body , context )
2842+ cla .log .info (
2843+ f"Successfully posted status '{ state } ' on PR { pull_request .number } : Commit { commit_hash } "
2844+ f"with SignUrl : { sign_url } with response: { resp } "
2845+ )
2846+ except GithubException as exc :
2847+ cla .log .error (
2848+ f"Could not post status '{ state } ' on PR: { pull_request .number } , "
2849+ f"Commit: { commit_hash } , "
2850+ f"Response Code: { exc .status } , "
2851+ f"Message: { exc .data } "
2852+ )
28112853
2812- def create_commit_status (commit_obj , state , sign_url , body , context ):
2854+ def create_commit_status (commit_obj , pull_request , last_commit_sha , state , sign_url , body , context ):
28132855 """
28142856 Helper function to create a commit status message given the commit object.
28152857
@@ -2823,20 +2865,21 @@ def create_commit_status(commit_obj, state, sign_url, body, context):
28232865 :type body: string
28242866 """
28252867 try :
2826- sha = getattr (commit_obj , "sha" , "(unknown)" )
2868+ sha = getattr (commit_obj , "sha" , last_commit_sha )
28272869 resp = commit_obj .create_status (state , sign_url , body , context )
28282870 cla .log .info (
2829- f"Successfully posted status '{ state } ': Commit { sha } "
2871+ f"Successfully posted status '{ state } ': Commit { sha } , PR: { pull_request . number } "
28302872 f"with SignUrl: { sign_url } with response: { resp } "
28312873 )
28322874 except GithubException as exc :
2833- sha = getattr (commit_obj , "sha" , "(unknown)" )
2834- cla .log .error (
2875+ sha = getattr (commit_obj , "sha" , last_commit_sha )
2876+ cla .log .warning (
28352877 f"Could not post status '{ state } ' on "
28362878 f"Commit: { sha } , "
28372879 f"Response Code: { exc .status } , "
28382880 f"Message: { exc .data } "
28392881 )
2882+ create_commit_status_pr_hash (pull_request , last_commit_sha , state , sign_url , body , context )
28402883
28412884# def update_cla_comment(pull_request, body):
28422885# """
0 commit comments