-
Notifications
You must be signed in to change notification settings - Fork 160
#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
2
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -627,6 +627,12 @@ type UserSettings struct { | |
| Notifications bool `json:"notifications"` | ||
| } | ||
|
|
||
| type GithubStatus struct { | ||
| Message string `json:"message"` | ||
| Emoji string `json:"emoji"` | ||
| Busy bool `json:"busy"` | ||
| } | ||
|
|
||
| func (p *Plugin) storeGitHubUserInfo(info *GitHubUserInfo) error { | ||
| config := p.getConfiguration() | ||
|
|
||
|
|
@@ -711,6 +717,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 +1202,71 @@ 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 userStatus.Status == "ooo" { | ||
| graphQLClient := p.graphQLConnect(userInfo) | ||
| message, emoji, busy, err := graphQLClient.GetUserStatus(context.Background(), userInfo.GitHubUsername) | ||
| 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") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @akshat-khosya this is cool feature. One minor issue I see is that a user's status will be left in the KV store if they disconnect their account while in "ooo" status. Can you add something to clear a user's status in the KV store when their account is disconnected? |
||
| p.CreateBotDMPost(userInfo.UserID, "Your GitHub status has been restored.", "custom_git_status_sync") | ||
| } | ||
| } | ||
| } | ||
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.
Can you check here if the Github status is already "out of office" and not overwrite it if true. I don't think we want to clobber a manually set OoO on the Github side.