Skip to content
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

[MM-617]: converted the custom post to slack attachment for issue creation event on Github #37

Merged
merged 12 commits into from
Aug 6, 2024
12 changes: 6 additions & 6 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ const (
WebsocketEventOpenStatusModal string = "open_status_modal"
WebsocketEventOpenEditModal string = "open_edit_modal"

OpenCommentModalPath string = "/open-comment-modal"
OpenEditIssueModalPath string = "/open-edit-modal"
OpenStatusModalPath string = "/open-status-modal"
OpenIssueCommentModalPath string = "/open-comment-modal"
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved
OpenIssueEditModalPath string = "/open-edit-modal"
OpenIssueStatusModalPath string = "/open-status-modal"
)

func (p *Plugin) writeJSON(w http.ResponseWriter, v interface{}) {
Expand Down Expand Up @@ -140,9 +140,9 @@ func (p *Plugin) initializeAPI() {
apiRouter.HandleFunc("/issue", p.checkAuth(p.attachUserContext(p.getIssueByNumber), ResponseTypePlain)).Methods(http.MethodGet)
apiRouter.HandleFunc("/pr", p.checkAuth(p.attachUserContext(p.getPrByNumber), ResponseTypePlain)).Methods(http.MethodGet)
apiRouter.HandleFunc("/lhs-content", p.checkAuth(p.attachUserContext(p.getSidebarContent), ResponseTypePlain)).Methods(http.MethodGet)
apiRouter.HandleFunc("/open-comment-modal", p.checkAuth(p.attachUserContext(p.handleOpenIssueCommentModal), ResponseTypePlain)).Methods(http.MethodPost)
apiRouter.HandleFunc("/open-edit-modal", p.checkAuth(p.attachUserContext(p.handleOpenEditIssueModal), ResponseTypePlain)).Methods(http.MethodPost)
apiRouter.HandleFunc("/open-status-modal", p.checkAuth(p.attachUserContext(p.handleOpenIssueStatusModal), ResponseTypePlain)).Methods(http.MethodPost)
apiRouter.HandleFunc(OpenIssueCommentModalPath, p.checkAuth(p.attachUserContext(p.handleOpenIssueCommentModal), ResponseTypePlain)).Methods(http.MethodPost)
apiRouter.HandleFunc(OpenIssueEditModalPath, p.checkAuth(p.attachUserContext(p.handleOpenEditIssueModal), ResponseTypePlain)).Methods(http.MethodPost)
apiRouter.HandleFunc(OpenIssueStatusModalPath, p.checkAuth(p.attachUserContext(p.handleOpenIssueStatusModal), ResponseTypePlain)).Methods(http.MethodPost)

apiRouter.HandleFunc("/config", checkPluginRequest(p.getConfig)).Methods(http.MethodGet)
apiRouter.HandleFunc("/token", checkPluginRequest(p.getToken)).Methods(http.MethodGet)
Expand Down
2 changes: 1 addition & 1 deletion server/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1097,5 +1097,5 @@ func (p *Plugin) getUsername(mmUserID string) (string, error) {
}

func (p *Plugin) GetPluginAPIPath() string {
return fmt.Sprintf("%s/plugins/github/api/v1", *p.client.Configuration.GetConfig().ServiceSettings.SiteURL)
return fmt.Sprintf("%s/plugins/%s/api/v1", *p.client.Configuration.GetConfig().ServiceSettings.SiteURL, Manifest.Id)
}
2 changes: 2 additions & 0 deletions server/plugin/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func (p *Plugin) updatePost(issue *UpdateIssueRequest, w http.ResponseWriter) {

attachments, err := getAttachmentsFromProps(post.Props)
if err != nil {
p.client.Log.Warn("Error occurred while getting attachments from props. PostID: %v. Error: %v", post.Id, err)
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved
p.writeAPIError(w, &APIErrorResponse{ID: "", Message: fmt.Sprintf("existing attachments format error: %v", err), StatusCode: http.StatusInternalServerError})
return
}
Expand Down Expand Up @@ -533,6 +534,7 @@ func (p *Plugin) CloseOrReopenIssue(c *UserContext, w http.ResponseWriter, statu

attachment, err := getAttachmentsFromProps(post.Props)
if err != nil {
c.Log.WithError(err).Warnf("Error occurred while getting attachments from props. PostID: %v.", post.Id)
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved
p.writeAPIError(w, &APIErrorResponse{ID: "", Message: fmt.Sprintf("existing attachments format error: %v", err), StatusCode: http.StatusInternalServerError})
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved
return
}
Expand Down
6 changes: 3 additions & 3 deletions server/plugin/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ func (p *Plugin) postIssueEvent(event *github.IssuesEvent) {
KeyIssueID: issue.GetID(),
KeyStatus: *issue.State,
},
URL: fmt.Sprintf("%s%s", p.GetPluginAPIPath(), OpenCommentModalPath),
URL: fmt.Sprintf("%s%s", p.GetPluginAPIPath(), OpenIssueCommentModalPath),
},
Style: "primary",
},
Expand All @@ -628,7 +628,7 @@ func (p *Plugin) postIssueEvent(event *github.IssuesEvent) {
KeyIssueID: issue.GetID(),
KeyStatus: *issue.State,
},
URL: fmt.Sprintf("%s%s", p.GetPluginAPIPath(), OpenEditIssueModalPath),
URL: fmt.Sprintf("%s%s", p.GetPluginAPIPath(), OpenIssueEditModalPath),
},
},
{
Expand All @@ -641,7 +641,7 @@ func (p *Plugin) postIssueEvent(event *github.IssuesEvent) {
KeyIssueID: issue.GetID(),
KeyStatus: *issue.State,
},
URL: fmt.Sprintf("%s%s", p.GetPluginAPIPath(), OpenStatusModalPath),
URL: fmt.Sprintf("%s%s", p.GetPluginAPIPath(), OpenIssueStatusModalPath),
},
},
},
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/components/modals/close_reopen_issue/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ const CloseOrReopenIssueModal = ({theme}: {theme: Theme}) => {
const handleIssueCommentChange = (updatedComment: string) => setComment(updatedComment);

const style = getStyle(theme);
const modalTitle = messageData.status === 'open' ? 'Close Issue' : 'Open Issue';
const issueAction = messageData.status === 'open' ? 'Close Issue' : 'Open Issue';
const modalTitle = issueAction;
const status = issueAction;
const savingMessage = messageData.status === 'open' ? 'Closing' : 'Reopening';
const status = messageData.status === 'open' ? 'Close Issue' : 'Open Issue';
const submitError = null;

const component = (messageData.status === 'open') ? (
Expand Down