Repository: mattermost/mattermost-plugin-github
Pull request #738 (2024-02-07 03:51:23)

Update CODEOWNERS to include mickmister
#### Summary

Adding myself as a code owner to the GitHub plugin to surface new PRs as review requests

codecov-commenter: ## [Codecov](https://app.codecov.io/gh/mattermost/mattermost-plugin-github/pull/738?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mattermost) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`2608197`)](https://app.codecov.io/gh/mattermost/mattermost-plugin-github/commit/2608197665120cdd99d5deae9fb01fe7bee6f20e?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mattermost) 15.78% compared to head [(`52a5779`)](https://app.codecov.io/gh/mattermost/mattermost-plugin-github/pull/738?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mattermost) 15.78%.


<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##           master     #738   +/-   ##
=======================================
  Coverage   15.78%   15.78%           
=======================================
  Files          15       15           
  Lines        5770     5770           
=======================================
  Hits          911      911           
  Misses       4817     4817           
  Partials       42       42           
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/mattermost/mattermost-plugin-github/pull/738?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mattermost).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=mattermost).


Patch:
diff --git a/CODEOWNERS b/CODEOWNERS
index 917242b..d0000d9 100644
--- a/CODEOWNERS
+++ b/CODEOWNERS
@@ -1,1 +1,1 @@
-* @hanzei
+* @hanzei @mickmister
diff --git a/README.md b/README.md
index 031af8d..bff96b9 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
 [![HW](https://img.shields.io/github/issues/mattermost/mattermost-plugin-github/Up%20For%20Grabs?color=dark%20green&label=Help%20Wanted)](https://github.com/mattermost/mattermost-plugin-github/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22Up+For+Grabs%22+label%3A%22Help+Wanted%22)
 
 **Maintainer:** [@hanzei](https://github.com/hanzei)
-**Co-Maintainer:** [@larkox](https://github.com/larkox)
+**Co-Maintainer:** [@mickmister](https://github.com/mickmister)
 
 A GitHub plugin for Mattermost. Supports GitHub SaaS and Enterprise versions.
 
diff --git a/plugin.json b/plugin.json
index 03a837a..0dd7b64 100644
--- a/plugin.json
+++ b/plugin.json
@@ -118,6 +118,13 @@
                 "type": "bool",
                 "help_text": "Allow the plugin to log the webhook event. The log level needs to be set to DEBUG.",
                 "default": false
+            },
+            {
+                "key": "ShowAuthorInCommitNotification",
+                "display_name": "Show Author in commit notification:",
+                "type": "bool",
+                "help_text": "In `Pushes` event notification, show commit author instead of commit committer.",
+                "default": false
             }
         ],
         "footer": "* To report an issue, make a suggestion or a contribution, [check the repository](https://github.com/mattermost/mattermost-plugin-github)."
diff --git a/server/plugin/configuration.go b/server/plugin/configuration.go
index d320c7d..5f25cff 100644
--- a/server/plugin/configuration.go
+++ b/server/plugin/configuration.go
@@ -25,19 +25,20 @@ import (
 // If you add non-reference types to your configuration struct, be sure to rewrite Clone as a deep
 // copy appropriate for your types.
 type Configuration struct {
-	GitHubOrg                   string `json:"githuborg"`
-	GitHubOAuthClientID         string `json:"githuboauthclientid"`
-	GitHubOAuthClientSecret     string `json:"githuboauthclientsecret"`
-	WebhookSecret               string `json:"webhooksecret"`
-	EnableLeftSidebar           bool   `json:"enableleftsidebar"`
-	EnablePrivateRepo           bool   `json:"enableprivaterepo"`
-	ConnectToPrivateByDefault   bool   `json:"connecttoprivatebydefault"`
-	EncryptionKey               string `json:"encryptionkey"`
-	EnterpriseBaseURL           string `json:"enterprisebaseurl"`
-	EnterpriseUploadURL         string `json:"enterpriseuploadurl"`
-	EnableCodePreview           string `json:"enablecodepreview"`
-	EnableWebhookEventLogging   bool   `json:"enablewebhookeventlogging"`
-	UsePreregisteredApplication bool   `json:"usepreregisteredapplication"`
+	GitHubOrg                      string `json:"githuborg"`
+	GitHubOAuthClientID            string `json:"githuboauthclientid"`
+	GitHubOAuthClientSecret        string `json:"githuboauthclientsecret"`
+	WebhookSecret                  string `json:"webhooksecret"`
+	EnableLeftSidebar              bool   `json:"enableleftsidebar"`
+	EnablePrivateRepo              bool   `json:"enableprivaterepo"`
+	ConnectToPrivateByDefault      bool   `json:"connecttoprivatebydefault"`
+	EncryptionKey                  string `json:"encryptionkey"`
+	EnterpriseBaseURL              string `json:"enterprisebaseurl"`
+	EnterpriseUploadURL            string `json:"enterpriseuploadurl"`
+	EnableCodePreview              string `json:"enablecodepreview"`
+	EnableWebhookEventLogging      bool   `json:"enablewebhookeventlogging"`
+	UsePreregisteredApplication    bool   `json:"usepreregisteredapplication"`
+	ShowAuthorInCommitNotification bool   `json:"showauthorincommitnotification"`
 }
 
 func (c *Configuration) ToMap() (map[string]interface{}, error) {
diff --git a/server/plugin/template.go b/server/plugin/template.go
index 46769ba..82b47fd 100644
--- a/server/plugin/template.go
+++ b/server/plugin/template.go
@@ -8,6 +8,7 @@ import (
 	"text/template"
 
 	"github.com/Masterminds/sprig/v3"
+	"github.com/google/go-github/v41/github"
 	"github.com/pkg/errors"
 )
 
@@ -32,6 +33,7 @@ var mdCommentRegex = regexp.MustCompile(mdCommentRegexPattern)
 var gitHubUsernameRegex = regexp.MustCompile(gitHubUsernameRegexPattern)
 var masterTemplate *template.Template
 var gitHubToUsernameMappingCallback func(string) string
+var showAuthorInCommitNotification bool
 
 func init() {
 	var funcMap = sprig.TxtFuncMap()
@@ -103,6 +105,14 @@ func init() {
 		return dict, nil
 	}
 
+	funcMap["commitAuthor"] = func(commit *github.HeadCommit) *github.CommitAuthor {
+		if showAuthorInCommitNotification {
+			return commit.GetAuthor()
+		}
+
+		return commit.GetCommitter()
+	}
+
 	masterTemplate = template.Must(template.New("master").Funcs(funcMap).Parse(""))
 
 	// The user template links to the corresponding GitHub user. If the GitHub user is a known
@@ -273,7 +283,7 @@ Assignees: {{range $i, $el := .Assignees -}} {{- if $i}}, {{end}}{{template "use
 	template.Must(masterTemplate.New("pushedCommits").Funcs(funcMap).Parse(`
 {{template "user" .GetSender}} {{if .GetForced}}force-{{end}}pushed [{{len .Commits}} new commit{{if ne (len .Commits) 1}}s{{end}}]({{.GetCompare}}) to [\[{{.GetRepo.GetFullName}}:{{.GetRef | trimRef}}\]]({{.GetRepo.GetHTMLURL}}/tree/{{.GetRef | trimRef}}):
 {{range .Commits -}}
-[` + "`{{.GetID | substr 0 6}}`" + `]({{.GetURL}}) {{.GetMessage}} - {{.GetCommitter.GetName}}
+[` + "`{{.GetID | substr 0 6}}`" + `]({{.GetURL}}) {{.GetMessage}} - {{with . | commitAuthor}}{{.GetName}}{{end}}
 {{end -}}
 `))
 
@@ -433,6 +443,10 @@ func lookupMattermostUsername(githubUsername string) string {
 	return gitHubToUsernameMappingCallback(githubUsername)
 }
 
+func setShowAuthorInCommitNotification(value bool) {
+	showAuthorInCommitNotification = value
+}
+
 func renderTemplate(name string, data interface{}) (string, error) {
 	var output bytes.Buffer
 	t := masterTemplate.Lookup(name)
diff --git a/server/plugin/webhook.go b/server/plugin/webhook.go
index c2225e8..6e1126a 100644
--- a/server/plugin/webhook.go
+++ b/server/plugin/webhook.go
@@ -657,6 +657,7 @@ func (p *Plugin) postPushEvent(event *github.PushEvent) {
 		return
 	}
 
+	setShowAuthorInCommitNotification(p.configuration.ShowAuthorInCommitNotification)
 	pushedCommitsMessage, err := renderTemplate("pushedCommits", event)
 	if err != nil {
 		p.client.Log.Warn("Failed to render template", "error", err.Error())
diff --git a/webapp/src/components/link_tooltip/link_tooltip.jsx b/webapp/src/components/link_tooltip/link_tooltip.jsx
index 4ba3dc9..806f79c 100644
--- a/webapp/src/components/link_tooltip/link_tooltip.jsx
+++ b/webapp/src/components/link_tooltip/link_tooltip.jsx
@@ -7,6 +7,8 @@ import ReactMarkdown from 'react-markdown';
 import Client from 'client';
 import {getLabelFontColor, hexToRGB} from '../../utils/styles';
 
+const maxTicketDescriptionLength = 160;
+
 export const LinkTooltip = ({href, connected, show, theme}) => {
     const [data, setData] = useState(null);
     useEffect(() => {
@@ -87,6 +89,14 @@ export const LinkTooltip = ({href, connected, show, theme}) => {
         let date = new Date(data.created_at);
         date = date.toDateString();
 
+        let description = '';
+        if (data.body) {
+            description = data.body.substring(0, maxTicketDescriptionLength).trim();
+            if (data.body.length > maxTicketDescriptionLength) {
+                description += '...';
+            }
+        }
+
         return (
             <div className='github-tooltip'>
                 <div
@@ -118,10 +128,7 @@ export const LinkTooltip = ({href, connected, show, theme}) => {
                                 <span>{'#' + data.number}</span>
                             </a>
                             <div className='markdown-text mt-1 mb-1'>
-                                <ReactMarkdown
-                                    source={data.body}
-                                    linkTarget='_blank'
-                                />
+                                <ReactMarkdown linkTarget='_blank'>{description}</ReactMarkdown>
                             </div>
 
                             {/* base <- head */}
@@ -141,14 +148,6 @@ export const LinkTooltip = ({href, connected, show, theme}) => {
                                 </div>
                             )}
 
-                            <div className='see-more mt-1'>
-                                <a
-                                    href={href}
-                                    target='_blank'
-                                    rel='noopener noreferrer'
-                                >{'See more'}</a>
-                            </div>
-
                             {/* Labels */}
                             <div className='labels mt-3'>
                                 {data.labels && data.labels.map((label, idx) => {


Test patch:
diff --git a/server/plugin/template_test.go b/server/plugin/template_test.go
index 5545c31..929dd9a 100644
--- a/server/plugin/template_test.go
+++ b/server/plugin/template_test.go
@@ -750,6 +750,41 @@ func TestPushedCommitsTemplate(t *testing.T) {
 		require.NoError(t, err)
 		require.Equal(t, expected, actual)
 	})
+
+	t.Run("single commit, with 'Show Author in commit notifications'", func(t *testing.T) {
+		showAuthorInCommitNotification = true
+		t.Cleanup(func() {
+			showAuthorInCommitNotification = false
+		})
+
+		expected := `
+[panda](https://github.com/panda) pushed [1 new commit](https://github.com/mattermost/mattermost-plugin-github/compare/master...branch) to [\[mattermost-plugin-github:branch\]](https://github.com/mattermost/mattermost-plugin-github/tree/branch):
+[` + "`a10867`" + `](https://github.com/mattermost/mattermost-plugin-github/commit/a10867b14bb761a232cd80139fbd4c0d33264240) Leverage git-get-head - lion
+`
+
+		actual, err := renderTemplate("pushedCommits", &github.PushEvent{
+			Repo:   &pushEventRepository,
+			Sender: &user,
+			Forced: bToP(false),
+			Commits: []*github.HeadCommit{
+				{
+					ID:      sToP("a10867b14bb761a232cd80139fbd4c0d33264240"),
+					URL:     sToP("https://github.com/mattermost/mattermost-plugin-github/commit/a10867b14bb761a232cd80139fbd4c0d33264240"),
+					Message: sToP("Leverage git-get-head"),
+					Committer: &github.CommitAuthor{
+						Name: sToP("panda"),
+					},
+					Author: &github.CommitAuthor{
+						Name: sToP("lion"),
+					},
+				},
+			},
+			Compare: sToP("https://github.com/mattermost/mattermost-plugin-github/compare/master...branch"),
+			Ref:     sToP("refs/heads/branch"),
+		})
+		require.NoError(t, err)
+		require.Equal(t, expected, actual)
+	})
 }
 
 func TestCreateMessageTemplate(t *testing.T) {