Skip to content

Commit fc16fe0

Browse files
Merge pull request #4832 from linuxfoundation/unicron-fix-get-latest-commit-main
Unicron fix get latest commit main
2 parents 4253010 + 2bd7f43 commit fc16fe0

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

cla-backend-go/github/github_repository.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,31 @@ func EditIssueCommentIfChanged(ctx context.Context, client *github.Client, owner
15231523
func GetPRHeadSHA(ctx context.Context, gh *github.Client, owner, repo string, prNumber int) (string, error) {
15241524
pr, _, err := gh.PullRequests.Get(ctx, owner, repo, prNumber)
15251525
if err != nil {
1526-
return "", err
1526+
f := logrus.Fields{
1527+
"functionName": "github.github_repository.GetPRHeadSHA",
1528+
"owner": owner,
1529+
"repo": repo,
1530+
"pullRequestID": prNumber,
1531+
}
1532+
log.WithFields(f).WithError(err).Warn("cannot get PR head SHA using PullRequests.Get, trying PullRequests.ListCommits")
1533+
opts := &github.ListOptions{PerPage: 1}
1534+
commits, resp, comErr := gh.PullRequests.ListCommits(ctx, owner, repo, prNumber, opts)
1535+
if comErr != nil {
1536+
log.WithFields(f).WithError(comErr).Warnf("problem listing commits for repo: %s/%s pull request: %d", owner, repo, prNumber)
1537+
return "", comErr
1538+
}
1539+
if resp != nil && resp.LastPage > 1 {
1540+
opts.Page = resp.LastPage
1541+
commits, _, comErr = gh.PullRequests.ListCommits(ctx, owner, repo, prNumber, opts)
1542+
if comErr != nil {
1543+
log.WithFields(f).WithError(comErr).Warnf("problem listing commits for repo: %s/%s pull request: %d (last page)", owner, repo, prNumber)
1544+
return "", comErr
1545+
}
1546+
}
1547+
if len(commits) == 0 || commits[0].SHA == nil {
1548+
return "", fmt.Errorf("missing head SHA for %s/%s PR #%d (via ListCommits)", owner, repo, prNumber)
1549+
}
1550+
return *commits[0].SHA, nil
15271551
}
15281552
sha := ""
15291553
if pr.Head != nil && pr.Head.SHA != nil {

cla-backend/cla/models/github_models.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,11 +2641,24 @@ def update_pull_request(
26412641
fn = "cla.models.github_models.update_pull_request"
26422642
notification = cla.conf["GITHUB_PR_NOTIFICATION"]
26432643
both = notification == "status+comment" or notification == "comment+status"
2644-
last_commit_sha = getattr(getattr(pull_request, "head", None), "sha", None)
2644+
cla.log.debug(f"{fn} - Updating PR {pull_request.number} with notification={notification}, both={both}")
2645+
try:
2646+
last_commit_sha = getattr(getattr(pull_request, "head", None), "sha", None)
2647+
repo = getattr(getattr(pull_request, "head", None), "repo", None)
2648+
if repo is None:
2649+
repo = getattr(getattr(pull_request, "base", None), "repo", None)
2650+
commit_obj = repo.get_commit(last_commit_sha)
2651+
except (GithubException, AttributeError, TypeError) as exc:
2652+
cla.log.error(f"{fn} - PR {pull_request.number}: exception getting head.sha: {exc}")
2653+
try:
2654+
commit_obj = pull_request.get_commits().reversed[0]
2655+
last_commit_sha = commit_obj.sha
2656+
except Exception as exc2:
2657+
cla.log.error(f"{fn} - PR {pull_request.number}: exception getting last commit from PR commits: {exc2}")
2658+
last_commit_sha = None
26452659
if not last_commit_sha:
26462660
cla.log.error(f"{fn} - PR {pull_request.number}: missing head.sha; cannot create statuses")
26472661
return
2648-
commit_obj = pull_request.base.repo.get_commit(last_commit_sha)
26492662

26502663
# Here we update the PR status by adding/updating the PR body - this is the way the EasyCLA app
26512664
# knows if it is pass/fail.
@@ -2814,7 +2827,7 @@ def create_commit_status(commit_obj, state, sign_url, body, context):
28142827
resp = commit_obj.create_status(state, sign_url, body, context)
28152828
cla.log.info(
28162829
f"Successfully posted status '{state}': Commit {sha} "
2817-
f"with SignUrl : {sign_url} with response: {resp}"
2830+
f"with SignUrl: {sign_url} with response: {resp}"
28182831
)
28192832
except GithubException as exc:
28202833
sha = getattr(commit_obj, "sha", "(unknown)")

utils/search_aws_log_group.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
# STAGE=dev DEBUG=1 DTFROM='3 days ago' DTTO='2 days ago' ./utils/search_aws_log_group.sh 'cla-backend-dev-githubactivity' 'error'
33
# STAGE=dev DEBUG=1 DTFROM='3 days ago' DTTO='2 days ago' ./utils/search_aws_log_group.sh 'cla-backend-dev-githubactivity' 'Runtime exited with'
4+
# STAGE=dev DEBUG=1 DTFROM='3 days ago' DTTO='2 days ago' ./utils/search_aws_log_group.sh 'cla-backend-dev-githubactivity' 'Traceback'
45
# STAGE=dev DEBUG=1 DTFROM='3 days ago' DTTO='2 days ago' ./utils/search_aws_log_group.sh 'cla-backend-dev-githubactivity' '---' # all
56
# REGION=us-east-2 STAGE=prod DEBUG=1 DTFROM='15 minutes ago' DTTO='1 second ago' ./utils/search_aws_log_group.sh 'cla-backend-go-api-v4-lambda' 'LG:api-request-path'
67
# REGION=us-east-1 STAGE=prod DEBUG=1 DTFROM='15 minutes ago' DTTO='1 second ago' ./utils/search_aws_log_group.sh 'cla-backend-prod-api-v3-lambda' 'LG:api-request-path'

0 commit comments

Comments
 (0)