|
| 1 | +// Copyright The Linux Foundation and each contributor to CommunityBridge. |
| 2 | +// SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +package github |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + gh "github.com/google/go-github/v37/github" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | +) |
| 12 | + |
| 13 | +func TestGetCommentBodyIncludesCoAuthorRemovalGuidance(t *testing.T) { |
| 14 | + signed := []*UserCommitSummary{{ |
| 15 | + SHA: "abc1234xyz-123", |
| 16 | + CommitAuthor: &gh.User{ |
| 17 | + ID: gh.Int64(1234), |
| 18 | + Login: gh.String("login_value"), |
| 19 | + Name: gh.String("author name"), |
| 20 | + Email: gh.String("foo@bar.com"), |
| 21 | + }, |
| 22 | + Affiliated: true, |
| 23 | + Authorized: true, |
| 24 | + }} |
| 25 | + |
| 26 | + missing := []*UserCommitSummary{{ |
| 27 | + SHA: "some_other_sha", |
| 28 | + CommitAuthor: &gh.User{ |
| 29 | + ID: gh.Int64(123456), |
| 30 | + Login: gh.String("login_value2"), |
| 31 | + Name: gh.String("author name2"), |
| 32 | + Email: gh.String("foo2@bar.com"), |
| 33 | + }, |
| 34 | + Affiliated: false, |
| 35 | + Authorized: false, |
| 36 | + }} |
| 37 | + |
| 38 | + body := getCommentBody("github", "https://foo.com", signed, missing, true) |
| 39 | + |
| 40 | + assert.Contains(t, body, "One or more co-authors of this pull request were not found") |
| 41 | + assert.Contains(t, body, "Alternatively, if the co-author should not be included, remove the `Co-authored-by:` line from the commit message.") |
| 42 | + assert.NotContains(t, body, "|Co-authored-by:|") |
| 43 | +} |
| 44 | + |
| 45 | +func TestGetCommentBodyOmitsCoAuthorRemovalGuidanceWhenNoCoAuthorIsMissing(t *testing.T) { |
| 46 | + missing := []*UserCommitSummary{{ |
| 47 | + SHA: "some_other_sha", |
| 48 | + CommitAuthor: &gh.User{ |
| 49 | + ID: gh.Int64(123456), |
| 50 | + Login: gh.String("login_value2"), |
| 51 | + Name: gh.String("author name2"), |
| 52 | + Email: gh.String("foo2@bar.com"), |
| 53 | + }, |
| 54 | + Affiliated: false, |
| 55 | + Authorized: false, |
| 56 | + }} |
| 57 | + |
| 58 | + body := getCommentBody("github", "https://foo.com", nil, missing, false) |
| 59 | + |
| 60 | + assert.NotContains(t, body, "One or more co-authors of this pull request were not found") |
| 61 | + assert.NotContains(t, body, "Alternatively, if the co-author should not be included, remove the `Co-authored-by:` line from the commit message.") |
| 62 | +} |
0 commit comments