Skip to content

Commit

Permalink
Remove useage of p.API
Browse files Browse the repository at this point in the history
  • Loading branch information
hanzei committed Feb 16, 2024
1 parent a75a9de commit 3f0f4fc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
26 changes: 13 additions & 13 deletions server/plugin/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ func (p *Plugin) createPost(channelID, userID, message string) error {
Message: message,
}

if _, appErr := p.API.CreatePost(post); appErr != nil {
p.API.LogWarn("Error while creating post", "Post", post, "Error", appErr.Error())
return appErr
if err := p.client.Post.CreatePost(post); err != nil {
p.client.Log.Warn("Error while creating post", "post", post, "error", err.Error())
return err
}

return nil
Expand All @@ -345,7 +345,7 @@ func (p *Plugin) checkIfConfiguredWebhookExists(ctx context.Context, githubClien
}

if err != nil {
p.API.LogWarn("Not able to get the list of webhooks", "Owner", owner, "Repo", repo, "Error", err.Error())
p.client.Log.Warn("Not able to get the list of webhooks", "Owner", owner, "Repo", repo, "error", err.Error())
return found, err
}

Expand Down Expand Up @@ -423,9 +423,9 @@ func (p *Plugin) handleSubscribesAdd(_ *plugin.Context, args *model.CommandArgs,

ctx := context.Background()
githubClient := p.githubConnectUser(ctx, userInfo)
user, appErr := p.API.GetUser(args.UserId)
if appErr != nil {
return errors.Wrap(appErr, "failed to get the user").Error()
user, err := p.client.User.Get(args.UserId)
if err != nil {
return errors.Wrap(err, "failed to get the user").Error()
}

owner, repo := parseOwnerAndRepo(parameters[0], baseURL)
Expand Down Expand Up @@ -492,7 +492,7 @@ func (p *Plugin) handleSubscribesAdd(_ *plugin.Context, args *model.CommandArgs,
}

if err = p.createPost(args.ChannelId, p.BotUserID, msg); err != nil {
return fmt.Sprintf("%s\nError creating the public post: %s", msg, appErr.Error())
return fmt.Sprintf("%s\nError creating the public post: %s", msg, err.Error())
}

found, err := p.checkIfConfiguredWebhookExists(ctx, githubClient, repo, owner)
Expand Down Expand Up @@ -546,15 +546,15 @@ func (p *Plugin) handleUnsubscribe(_ *plugin.Context, args *model.CommandArgs, p
owner = strings.ToLower(owner)
repo = strings.ToLower(repo)
if err := p.Unsubscribe(args.ChannelId, repo, owner); err != nil {
p.API.LogWarn("Failed to unsubscribe", "repo", repo, "error", err.Error())
p.client.Log.Warn("Failed to unsubscribe", "repo", repo, "error", err.Error())
return "Encountered an error trying to unsubscribe. Please try again."
}

baseURL := config.getBaseURL()
user, appErr := p.API.GetUser(args.UserId)
if appErr != nil {
p.API.LogWarn("Error while fetching user details", "Error", appErr.Error())
return fmt.Sprintf("error while fetching user details: %s", appErr.Error())
user, err := p.client.User.Get(args.UserId)
if err != nil {
p.client.Log.Warn("Error while fetching user details", "error", err.Error())
return fmt.Sprintf("error while fetching user details: %s", err.Error())
}

unsubscribeMessage := ""
Expand Down
2 changes: 1 addition & 1 deletion server/plugin/graphql/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewClient(logger pluginapi.LogService, token oauth2.Token, username, orgNam
} else {
baseURL, err := url.Parse(enterpriseBaseURL)
if err != nil {
logger.Debug("Not able to parse the URL", "Error", err.Error())
logger.Debug("Not able to parse the URL", "error", err.Error())
return nil
}

Expand Down
10 changes: 5 additions & 5 deletions server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (p *Plugin) OnDeactivate() error {
p.webhookBroker.Close()
p.oauthBroker.Close()
if err := p.telemetryClient.Close(); err != nil {
p.API.LogWarn("Telemetry client failed to close", "error", err.Error())
p.client.Log.Warn("Telemetry client failed to close", "error", err.Error())
}
return nil
}
Expand Down Expand Up @@ -659,7 +659,7 @@ func (p *Plugin) getGitHubToUserIDMapping(githubUsername string) string {
var data []byte
err := p.store.Get(githubUsername+githubUsernameKey, &data)
if err != nil {
p.API.LogWarn("Error occurred while getting the user ID from KV store using the Github username", "Error", err.Error())
p.client.Log.Warn("Error occurred while getting the user ID from KV store using the Github username", "error", err.Error())
return ""
}

Expand Down Expand Up @@ -1018,7 +1018,7 @@ func (p *Plugin) sendRefreshEvent(userID string) {

info, apiErr := p.getGitHubUserInfo(context.UserID)
if apiErr != nil {
p.API.LogWarn("Failed to get github user info", "error", apiErr.Error())
p.client.Log.Warn("Failed to get github user info", "error", apiErr.Error())
return
}

Expand All @@ -1029,13 +1029,13 @@ func (p *Plugin) sendRefreshEvent(userID string) {

sidebarContent, err := p.getSidebarData(userContext)
if err != nil {
p.API.LogWarn("Failed to get the sidebar data", "error", err.Error())
p.client.Log.Warn("Failed to get the sidebar data", "error", err.Error())
return
}

contentMap, err := sidebarContent.toMap()
if err != nil {
p.API.LogWarn("Failed to convert sidebar content to map", "error", err.Error())
p.client.Log.Warn("Failed to convert sidebar content to map", "error", err.Error())
return
}

Expand Down

0 comments on commit 3f0f4fc

Please sign in to comment.