-
Notifications
You must be signed in to change notification settings - Fork 167
#866 Set user as Busy in GitHub when status in Mattermost is OOO #940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
akshat-khosya
wants to merge
4
commits into
mattermost:master
Choose a base branch
from
akshat-khosya:issues-866
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+183
−8
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8394af6
feat: Sync Mattermost OOO status to GitHub
google-labs-jules[bot] 921e60d
Address PR feedback: Make status sync opt-in and fix issues
a5470b0
feat: add user opt-in for status synchronization
akshat-khosya 91bd732
removed server admin config for ooo sync and used StatusOutOfOffice v…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -625,6 +625,13 @@ type UserSettings struct { | |
| DailyReminder bool `json:"daily_reminder"` | ||
| DailyReminderOnChange bool `json:"daily_reminder_on_change"` | ||
| Notifications bool `json:"notifications"` | ||
| StatusSync bool `json:"status_sync"` | ||
| } | ||
|
|
||
| type GithubStatus struct { | ||
| Message string `json:"message"` | ||
| Emoji string `json:"emoji"` | ||
| Busy bool `json:"busy"` | ||
| } | ||
|
|
||
| func (p *Plugin) storeGitHubUserInfo(info *GitHubUserInfo) error { | ||
|
|
@@ -711,6 +718,10 @@ func (p *Plugin) disconnectGitHubAccount(userID string) { | |
| p.client.Log.Warn("Failed to delete github token from KV store", "userID", userID, "error", err.Error()) | ||
| } | ||
|
|
||
| if err := p.store.Delete(userID + "_github_status"); err != nil { | ||
| p.client.Log.Warn("Failed to delete github status from KV store", "userID", userID, "error", err.Error()) | ||
| } | ||
|
|
||
| user, err := p.client.User.Get(userID) | ||
| if err != nil { | ||
| p.client.Log.Warn("Failed to get user props", "userID", userID, "error", err.Error()) | ||
|
|
@@ -1192,3 +1203,75 @@ func (p *Plugin) handleRevokedToken(info *GitHubUserInfo) { | |
| p.disconnectGitHubAccount(info.UserID) | ||
| p.CreateBotDMPost(info.UserID, "Your Github account was disconnected due to an invalid or revoked authorization token. Reconnect your account using the `/github connect` command.", "custom_git_revoked_token") | ||
| } | ||
|
|
||
| func (p *Plugin) UserStatusHasChanged(c *plugin.Context, userStatus *model.Status) { | ||
| // Check if status sync is enabled in configuration | ||
| config := p.getConfiguration() | ||
| if !config.EnableStatusSync { | ||
| return | ||
| } | ||
|
|
||
| userInfo, apiErr := p.getGitHubUserInfo(userStatus.UserId) | ||
| if apiErr != nil { | ||
| return | ||
| } | ||
|
|
||
| if !userInfo.Settings.StatusSync { | ||
| return | ||
| } | ||
|
|
||
| if userStatus.Status == "ooo" { | ||
|
||
| graphQLClient := p.graphQLConnect(userInfo) | ||
| message, emoji, busy, err := graphQLClient.GetUserStatus(context.Background(), userInfo.GitHubUsername) | ||
wiggin77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| p.client.Log.Error("failed to get user status", "error", err) | ||
| return | ||
| } | ||
|
|
||
| // Don't overwrite if GitHub status is already set to "out of office" (busy) | ||
| if busy { | ||
| p.client.Log.Debug("GitHub status is already set to busy/OOO, skipping update") | ||
| return | ||
| } | ||
|
|
||
| githubStatus := &GithubStatus{ | ||
| Message: message, | ||
| Emoji: emoji, | ||
| Busy: busy, | ||
| } | ||
|
|
||
| githubStatusJSON, err := json.Marshal(githubStatus) | ||
| if err != nil { | ||
| p.client.Log.Error("failed to marshal github status", "error", err) | ||
| return | ||
| } | ||
|
|
||
| p.store.Set(userInfo.UserID+"_github_status", githubStatusJSON) | ||
|
|
||
| _, err = graphQLClient.UpdateUserStatus(context.Background(), ":house_with_garden:", "Out of office", true) | ||
| if err != nil { | ||
| p.client.Log.Error("failed to update user status", "error", err) | ||
| return | ||
| } | ||
|
|
||
| p.CreateBotDMPost(userInfo.UserID, "Your GitHub status has been updated to Out of office.", "custom_git_status_sync") | ||
| } else { | ||
| var oldStatus []byte | ||
| if err := p.store.Get(userInfo.UserID+"_github_status", &oldStatus); err == nil && len(oldStatus) > 0 { | ||
| var githubStatus GithubStatus | ||
| if err := json.Unmarshal(oldStatus, &githubStatus); err != nil { | ||
| p.client.Log.Error("failed to unmarshal github status", "error", err) | ||
| return | ||
| } | ||
|
|
||
| graphQLClient := p.graphQLConnect(userInfo) | ||
| _, err := graphQLClient.UpdateUserStatus(context.Background(), githubStatus.Emoji, githubStatus.Message, githubStatus.Busy) | ||
| if err != nil { | ||
| p.client.Log.Error("failed to update user status", "error", err) | ||
| return | ||
| } | ||
| p.store.Delete(userInfo.UserID + "_github_status") | ||
wiggin77 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| p.CreateBotDMPost(userInfo.UserID, "Your GitHub status has been restored.", "custom_git_status_sync") | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that users can opt-in directly and it's default off, do we need this at the server level? Removing this extra configuration will allow users to start enabling this without needing admins to turn it on