Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
cbb804e
[MI-2502]:Added custom type for webhook post in order to comment, edi…
Nityanand13 Jan 31, 2023
4378034
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
Nityanand13 Jan 31, 2023
20ab25d
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
Nityanand13 Feb 8, 2023
70ae885
[MI-2736]: Done the review fixes of a github PR #636 (#20)
Nityanand13 Feb 9, 2023
3cecd5d
[MI-2736]: Done the review fixes of a github PR #636 (#21)
Nityanand13 Feb 16, 2023
779f10f
[MI-2814] Done the review fixes of github PR #636 (#22)
Nityanand13 Mar 13, 2023
67c370b
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
Nityanand13 Mar 13, 2023
2de4435
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
ayusht2810 Apr 9, 2024
0f40aba
[MM-618] Update validations, modal title, styling, post messages, con…
ayusht2810 Apr 10, 2024
f4f5057
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
ayusht2810 Apr 24, 2024
9f7af14
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
ayusht2810 May 1, 2024
d0e7abd
[MM-618] Remove constants and serializers package
ayusht2810 May 1, 2024
1a279e8
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
ayusht2810 Jun 21, 2024
39fe3cf
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
raghavaggarwal2308 Jul 2, 2024
c5a8d29
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
raghavaggarwal2308 Jul 5, 2024
136221f
[MM-556] Review fixes
raghavaggarwal2308 Jul 5, 2024
482fcf9
[MM-617]: converted the custom post to slack attachment for issue cre…
Kshitij-Katiyar Aug 6, 2024
79c266e
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
Kshitij-Katiyar Aug 6, 2024
28300d5
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
Kshitij-Katiyar Aug 30, 2024
b413828
[MM-618]: Fixed the lint
Kshitij-Katiyar Aug 30, 2024
64655a0
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
Kshitij-Katiyar Sep 26, 2024
49daa01
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
Kshitij-Katiyar Jan 21, 2025
9ad7d48
fxed testcases
Kshitij-Katiyar Jan 21, 2025
90ec210
merge master to the PR
Kshitij-Katiyar Jan 31, 2025
25c1a3e
fixed lint
Kshitij-Katiyar Jan 31, 2025
f225e3a
merge master to bs/MM-618
Kshitij-Katiyar Apr 21, 2025
a4a0961
Merge branch 'master' of github.com:mattermost/mattermost-plugin-gith…
Kshitij-Katiyar Apr 21, 2025
762a353
updated snapshot
Kshitij-Katiyar Apr 21, 2025
5bd38eb
fixed lint
Kshitij-Katiyar Apr 21, 2025
fc3e0c0
convert comment custom post to interactive dialog
Kshitij-Katiyar Apr 21, 2025
a235186
convert close/reopen issue custom modal to interactive dialog
Kshitij-Katiyar Apr 25, 2025
ea9e9ef
convert edit issue custom modal to interactive dialog
Kshitij-Katiyar Apr 29, 2025
5e5e352
Lint fixes
Kshitij-Katiyar Apr 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,099 changes: 878 additions & 221 deletions server/plugin/api.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions server/plugin/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestPlugin_ServeHTTP(t *testing.T) {
p.SetAPI(&plugintest.API{})

req := test.httpTest.CreateHTTPRequest(test.request)
req.Header.Add("Mattermost-User-ID", test.userID)
req.Header.Add(headerMattermostUserID, test.userID)
rr := httptest.NewRecorder()
p.ServeHTTP(&plugin.Context{}, rr, req)
test.httpTest.CompareHTTPResponse(rr, test.expectedResponse)
Expand Down Expand Up @@ -356,7 +356,7 @@ func TestGetGitHubUser(t *testing.T) {

var response APIErrorResponse
_ = json.NewDecoder(rec.Body).Decode(&response)
assert.Contains(t, response.Message, "Please provide a JSON object.")
assert.Contains(t, response.Message, "Please provide a valid JSON object.")
},
},
{
Expand Down
2 changes: 1 addition & 1 deletion server/plugin/mm_34646_token_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (p *Plugin) forceResetUserTokenMM34646(ctx context.Context, config *Configu
info.MM34646ResetTokenDone = true
err = p.storeGitHubUserInfo(info)
if err != nil {
return "", errors.Wrap(err, "failed to store updated GitHubUserInfo")
return "", errors.Wrap(err, "failed to store updated serializer.GitHubUserInfo")
}
p.client.Log.Debug("Updated user access token for MM-34646", "user_id", info.UserID)

Expand Down
45 changes: 45 additions & 0 deletions server/plugin/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,58 @@ package plugin

import (
"sync"

"golang.org/x/oauth2"
)

type GitHubUserRequest struct {
UserID string `json:"user_id"`
}

type GitHubUserResponse struct {
Username string `json:"username"`
}

type ConnectedResponse struct {
Connected bool `json:"connected"`
GitHubUsername string `json:"github_username"`
GitHubClientID string `json:"github_client_id"`
EnterpriseBaseURL string `json:"enterprise_base_url,omitempty"`
Organizations []string `json:"organizations"`
UserSettings *UserSettings `json:"user_settings"`
ClientConfiguration map[string]interface{} `json:"configuration"`
}

type UserSettings struct {
SidebarButtons string `json:"sidebar_buttons"`
DailyReminder bool `json:"daily_reminder"`
DailyReminderOnChange bool `json:"daily_reminder_on_change"`
Notifications bool `json:"notifications"`
}

type GitHubUserInfo struct {
UserID string
Token *oauth2.Token
GitHubUsername string
LastToDoPostAt int64
Settings *UserSettings
AllowedPrivateRepos bool

// MM34646ResetTokenDone is set for a user whose token has been reset for MM-34646.
MM34646ResetTokenDone bool
}

type OAuthCompleteEvent struct {
UserID string
Err error
}

type OAuthState struct {
UserID string `json:"user_id"`
Token string `json:"token"`
PrivateAllowed bool `json:"private_allowed"`
}

type OAuthBroker struct {
sendOAuthCompleteEvent func(event OAuthCompleteEvent)

Expand Down
77 changes: 52 additions & 25 deletions server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"regexp"
"strings"
"sync"
"time"

"github.com/google/go-github/v54/github"
"github.com/gorilla/mux"
Expand All @@ -30,10 +31,14 @@ import (
)

const (
githubTokenKey = "_githubtoken"
githubOauthKey = "githuboauthkey_"
githubUsernameKey = "_githubusername"
githubPrivateRepoKey = "_githubprivate"
githubTokenKey = "_githubtoken"
githubOauthKey = "githuboauthkey_"
githubUsernameKey = "_githubusername"
githubPrivateRepoKey = "_githubprivate"
githubObjectTypeIssue = "issue"
githubObjectTypeIssueComment = "issue_comment"
githubObjectTypePRReviewComment = "pr_review_comment"
githubObjectTypeDiscussionComment = "discussion_comment"

mm34646MutexKey = "mm34646_token_reset_mutex"
mm34646DoneKey = "mm34646_token_reset_done"
Expand All @@ -59,6 +64,39 @@ const (

chimeraGitHubAppIdentifier = "plugin-github"

apiErrorIDNotConnected = "not_connected"

// TokenTTL is the OAuth token expiry duration in seconds
tokenTTL = 600

requestTimeout = 30 * time.Second
oauthCompleteTimeout = 2 * time.Minute
headerMattermostUserID = "Mattermost-User-ID"
ownerQueryParam = "owner"
repoQueryParam = "repo"
numberQueryParam = "number"
postIDQueryParam = "postId"
channelIDParam = "channelId"

issueStatus = "status"
assigneesForProps = "assignees"
labelsForProps = "labels"
descriptionForProps = "description"
titleForProps = "title"
attachmentsForProps = "attachments"
issueNumberForProps = "issue_number"
issueURLForProps = "issue_url"
repoOwnerForProps = "repo_owner"
repoNameForProps = "repo_name"

statusClose = "Close"
statusReopen = "Reopen"

issueCompleted = "completed"
issueNotPlanned = "not_planned"
issueClose = "closed"
issueOpen = "open"

invalidTokenError = "401 Bad credentials" //#nosec G101 -- False positive
)

Expand Down Expand Up @@ -604,25 +642,6 @@ func (p *Plugin) getOAuthConfigForChimeraApp(scopes []string) (*oauth2.Config, e
}, nil
}

type GitHubUserInfo struct {
UserID string
Token *oauth2.Token
GitHubUsername string
LastToDoPostAt int64
Settings *UserSettings
AllowedPrivateRepos bool

// MM34646ResetTokenDone is set for a user whose token has been reset for MM-34646.
MM34646ResetTokenDone bool
}

type UserSettings struct {
SidebarButtons string `json:"sidebar_buttons"`
DailyReminder bool `json:"daily_reminder"`
DailyReminderOnChange bool `json:"daily_reminder_on_change"`
Notifications bool `json:"notifications"`
}

func (p *Plugin) storeGitHubUserInfo(info *GitHubUserInfo) error {
config := p.getConfiguration()

Expand Down Expand Up @@ -1123,7 +1142,7 @@ func (p *Plugin) sendRefreshEvent(userID string) {
return
}

contentMap, err := sidebarContent.toMap()
contentMap, err := sidebarContent.ToMap()
if err != nil {
p.client.Log.Warn("Failed to convert sidebar content to map", "error", err.Error())
return
Expand All @@ -1136,7 +1155,7 @@ func (p *Plugin) sendRefreshEvent(userID string) {
)
}

func (s *SidebarContent) toMap() (map[string]interface{}, error) {
func (s *SidebarContent) ToMap() (map[string]interface{}, error) {
var m map[string]interface{}
bytes, err := json.Marshal(&s)
if err != nil {
Expand All @@ -1150,6 +1169,10 @@ func (s *SidebarContent) toMap() (map[string]interface{}, error) {
return m, nil
}

func (e *APIErrorResponse) Error() string {
return e.Message
}

// getUsername returns the GitHub username for a given Mattermost user,
// if the user is connected to GitHub via this plugin.
// Otherwise it return the Mattermost username. It will be escaped via backticks.
Expand All @@ -1171,6 +1194,10 @@ func (p *Plugin) getUsername(mmUserID string) (string, error) {
return "@" + info.GitHubUsername, nil
}

func (p *Plugin) GetPluginAPIPath() string {
return fmt.Sprintf("%s/plugins/%s/api/v1", *p.client.Configuration.GetConfig().ServiceSettings.SiteURL, Manifest.Id)
}

func (p *Plugin) useGitHubClient(info *GitHubUserInfo, toRun func(info *GitHubUserInfo, token *oauth2.Token) error) error {
err := toRun(info, info.Token)
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions server/plugin/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ const (
MockPostMessage = "mockPostMessage"
)

type GitHubUserResponse struct {
Username string `json:"username"`
}

func GetMockGHUserInfo(p *Plugin) (*GitHubUserInfo, error) {
encryptionKey := "dummyEncryptKey1"
p.setConfiguration(&Configuration{EncryptionKey: encryptionKey})
Expand Down
Loading
Loading