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

Some cleanup for Jira plugin #42

Merged
merged 13 commits into from
May 2, 2019
10 changes: 5 additions & 5 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "jira",
"name": "JIRA",
"description": "Atlassian JIRA plugin for Mattermost.",
"name": "Jira",
"description": "Atlassian Jira plugin for Mattermost.",
"version": "2.0.0",
"server": {
"executables": {
Expand All @@ -22,16 +22,16 @@
"help_text": "Select the username that this integration is attached to."
}, {
"key": "JiraServerURL",
"display_name": "JIRA Server URL",
"display_name": "Jira Server URL",
"type": "text",
"help_text": "URL of the JIRA Server to connect to, e.g. \"https://jira.internal.my-company-name.com\""
"help_text": "The URL for a self-hosted Jira server, e.g. \"https://jira.internal.my-company-name.com\""
}, {
"key": "Secret",
"display_name": "Secret",
"type": "generated",
"help_text": "This secret is used to authenticate to Mattermost.",
"regenerate_help_text": "Regenerates the secret for the webhook URL endpoint. Regenerating the secret invalidates your existing JIRA integrations."
}],
"footer": "Use this webhook URL to set up the JIRA integration. See [documentation](https://about.mattermost.com/default-jira-plugin) to learn more.\n\n`https://SITEURL/plugins/jira/webhook?secret=WEBHOOKSECRET&team=TEAMURL&channel=CHANNELURL`"
"footer": "Use this webhook URL to set up the Jira integration. See [documentation](https://about.mattermost.com/default-jira-plugin) to learn more.\n\n`https://SITEURL/plugins/jira/webhook?secret=WEBHOOKSECRET&team=TEAMURL&channel=CHANNELURL`"
}
}
4 changes: 2 additions & 2 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
config := p.getConfig()
if config.UserName == "" {
http.Error(w, "JIRA plugin not configured correctly; must provide UserName", http.StatusForbidden)
http.Error(w, "Jira plugin not configured correctly; must provide UserName", http.StatusForbidden)
return
}

Expand Down Expand Up @@ -75,7 +75,7 @@ func handleHTTPRequest(p *Plugin, w http.ResponseWriter, r *http.Request) (int,
case routeIncomingWebhook, routeIncomingIssueEvent:
return httpWebhook(p, w, r)

// Oauth1 (JIRA Server)
// Oauth1 (Jira Server)
case routeOAuth1Complete:
return httpOAuth1Complete(p, w, r)
case routeOAuth1PublicKey:
Expand Down
2 changes: 1 addition & 1 deletion server/instance_cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (jci jiraCloudInstance) GetJIRAClient(jiraUser JIRAUser) (*jira.Client, err
//TODO decide if we ever need this as the default client
// client, err = jci.getJIRAClientForServer()
if err != nil {
return nil, errors.WithMessage(err, "failed to get JIRA client for user "+jiraUser.Name)
return nil, errors.WithMessage(err, "failed to get Jira client for user "+jiraUser.Name)
}

return client, nil
Expand Down
2 changes: 1 addition & 1 deletion server/instance_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (jsi jiraServerInstance) GetJIRAClient(jiraUser JIRAUser) (returnClient *ji
if returnErr == nil {
return
}
returnErr = errors.WithMessage(returnErr, "failed to get a JIRA client for "+jiraUser.Name)
returnErr = errors.WithMessage(returnErr, "failed to get a Jira client for "+jiraUser.Name)
}()

if jiraUser.Oauth1AccessToken == "" || jiraUser.Oauth1AccessSecret == "" {
Expand Down
22 changes: 11 additions & 11 deletions server/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (p *Plugin) StoreJIRAInstance(ji Instance, current bool) (returnErr error)
return
}
returnErr = errors.WithMessage(returnErr,
fmt.Sprintf("failed to store JIRA instance:%+v", ji))
fmt.Sprintf("failed to store Jira instance:%+v", ji))
}()

err := p.kvSet(md5key(prefixJIRAInstance, ji.GetURL()), ji)
Expand All @@ -116,15 +116,15 @@ func (p *Plugin) StoreJIRAInstance(ji Instance, current bool) (returnErr error)
}
}

p.debugf("Stored: JIRA instance (current:%v): %#v", current, ji)
p.debugf("Stored: Jira instance (current:%v): %#v", current, ji)

return nil
}

func (p *Plugin) LoadCurrentJIRAInstance() (Instance, error) {
ji, err := p.loadJIRAInstance(keyCurrentJIRAInstance)
if err != nil {
return nil, errors.WithMessage(err, "failed to load current JIRA instance")
return nil, errors.WithMessage(err, "failed to load current Jira instance")
}

return ji, nil
Expand All @@ -133,7 +133,7 @@ func (p *Plugin) LoadCurrentJIRAInstance() (Instance, error) {
func (p *Plugin) LoadJIRAInstance(key string) (Instance, error) {
ji, err := p.loadJIRAInstance(md5key(prefixJIRAInstance, key))
if err != nil {
return nil, errors.WithMessage(err, "failed to load JIRA instance "+key)
return nil, errors.WithMessage(err, "failed to load Jira instance "+key)
}

return ji, nil
Expand Down Expand Up @@ -168,7 +168,7 @@ func (p *Plugin) loadJIRAInstance(fullkey string) (Instance, error) {
return jsi.InitWithPlugin(p), nil
}

return nil, errors.New(fmt.Sprintf("JIRA instance %s has unsupported type: %s", fullkey, jsi.Type))
return nil, errors.New(fmt.Sprintf("Jira instance %s has unsupported type: %s", fullkey, jsi.Type))
}

func (p *Plugin) StoreKnownJIRAInstances(known map[string]string) (returnErr error) {
Expand All @@ -177,7 +177,7 @@ func (p *Plugin) StoreKnownJIRAInstances(known map[string]string) (returnErr err
return
}
returnErr = errors.WithMessage(returnErr,
fmt.Sprintf("failed to store known JIRA instances %+v", known))
fmt.Sprintf("failed to store known Jira instances %+v", known))
}()

return p.kvSet(keyKnownJIRAInstances, known)
Expand All @@ -187,7 +187,7 @@ func (p *Plugin) LoadKnownJIRAInstances() (map[string]string, error) {
known := map[string]string{}
err := p.kvGet(keyKnownJIRAInstances, &known)
if err != nil {
return nil, errors.WithMessage(err, "failed to load known JIRA instances")
return nil, errors.WithMessage(err, "failed to load known Jira instances")
}
return known, nil
}
Expand All @@ -198,7 +198,7 @@ func (p *Plugin) StoreUserInfo(ji Instance, mattermostUserId string, jiraUser JI
return
}
returnErr = errors.WithMessage(returnErr,
fmt.Sprintf("failed to store JIRA user, mattermostUserId:%s, user:%#v", mattermostUserId, jiraUser))
fmt.Sprintf("failed to store Jira user, mattermostUserId:%s, user:%#v", mattermostUserId, jiraUser))
}()

err := p.kvSet(keyWithInstance(ji, mattermostUserId), jiraUser)
Expand All @@ -211,7 +211,7 @@ func (p *Plugin) StoreUserInfo(ji Instance, mattermostUserId string, jiraUser JI
return err
}

p.debugf("Stored: JIRA user, keys:\n\t%s (%s): %+v\n\t%s (%s): %s",
p.debugf("Stored: Jira user, keys:\n\t%s (%s): %+v\n\t%s (%s): %s",
keyWithInstance(ji, mattermostUserId), mattermostUserId, jiraUser,
keyWithInstance(ji, jiraUser.Name), jiraUser.Name, mattermostUserId)

Expand All @@ -225,7 +225,7 @@ func (p *Plugin) LoadJIRAUser(ji Instance, mattermostUserId string) (JIRAUser, e
err := p.kvGet(keyWithInstance(ji, mattermostUserId), &jiraUser)
if err != nil {
return JIRAUser{}, errors.WithMessage(err,
fmt.Sprintf("failed to load JIRA user for mattermostUserId:%s", mattermostUserId))
fmt.Sprintf("failed to load Jira user for mattermostUserId:%s", mattermostUserId))
}
if len(jiraUser.Key) == 0 {
return JIRAUser{}, ErrUserNotFound
Expand All @@ -238,7 +238,7 @@ func (p *Plugin) LoadMattermostUserId(ji Instance, jiraUserName string) (string,
err := p.kvGet(keyWithInstance(ji, jiraUserName), &mattermostUserId)
if err != nil {
return "", errors.WithMessage(err,
"failed to load Mattermost user ID for JIRA user: "+jiraUserName)
"failed to load Mattermost user ID for Jira user: "+jiraUserName)
}
if len(mattermostUserId) == 0 {
return "", ErrUserNotFound
Expand Down
4 changes: 2 additions & 2 deletions server/message_posted.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (p *Plugin) MessageHasBeenPosted(c *plugin.Context, post *model.Post) {
}

if channel.Type != model.CHANNEL_OPEN {
err = errors.New("ignoring JIRA comment in " + channel.Name)
err = errors.New("ignoring Jira comment in " + channel.Name)
return
}

Expand All @@ -80,7 +80,7 @@ func (p *Plugin) MessageHasBeenPosted(c *plugin.Context, post *model.Post) {

_, _, err := jiraClient.Issue.AddComment(issue, comment)
if err != nil {
p.errorf("MessageHasBeenPosted: failed to add the comment to JIRA, error: %v", err)
p.errorf("MessageHasBeenPosted: failed to add the comment to Jira, error: %v", err)
}
}
}
2 changes: 1 addition & 1 deletion server/templates/atlassian-connect.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"key": "{{ .Key }}",
"name": "Mattermost Plugin ({{ .ExternalURL }})",
"description": "Integrates JIRA with Mattermost for in-place interactions and notifications",
"description": "Integrates Jira with Mattermost for in-place interactions and notifications",
"vendor": {
"name": "Mattermost",
"url": "https://github.com/mattermost"
Expand Down
2 changes: 1 addition & 1 deletion server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func httpUserDisconnect(p *Plugin, w http.ResponseWriter, r *http.Request) (int,
</script>
</head>
<body>
<p>Disconnected from JIRA. Please close this page.</p>
<p>Disconnected from Jira. Please close this page.</p>
</body>
</html>
`
Expand Down
6 changes: 3 additions & 3 deletions server/user_atlassian_connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func httpACUserConfig(p *Plugin, w http.ResponseWriter, r *http.Request) (int, e
}
jci, ok := ji.(*jiraCloudInstance)
if !ok {
return http.StatusBadRequest, errors.New("Must be a JIRA Cloud instance, is " + ji.GetType())
return http.StatusBadRequest, errors.New("Must be a Jira Cloud instance, is " + ji.GetType())
}

_, tokenString, err := jci.parseHTTPRequestJWT(r)
Expand Down Expand Up @@ -62,7 +62,7 @@ func httpACUserConfigSubmit(p *Plugin, w http.ResponseWriter, r *http.Request) (
}
jci, ok := ji.(*jiraCloudInstance)
if !ok {
return http.StatusBadRequest, errors.New("Must be a JIRA Cloud instance, is " + ji.GetType())
return http.StatusBadRequest, errors.New("Must be a Jira Cloud instance, is " + ji.GetType())
}

jwtToken, _, err := jci.parseHTTPRequestJWT(r)
Expand Down Expand Up @@ -116,7 +116,7 @@ func httpACUserConfigSubmit(p *Plugin, w http.ResponseWriter, r *http.Request) (
<script src="https://connect-cdn.atl-paas.net/all.js" data-options=""></script>
</head>
<body>
granted Mattermost user ` + mmuser.GetDisplayName(model.SHOW_NICKNAME_FULLNAME) + " (" + mmuser.Username + `) access to JIRA as ` + displayName + " (" + username + `)
granted Mattermost user ` + mmuser.GetDisplayName(model.SHOW_NICKNAME_FULLNAME) + " (" + mmuser.Username + `) access to Jira as ` + displayName + " (" + username + `)
</body>
</html>`))
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions server/user_oauth1.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func httpOAuth1Complete(p *Plugin, w http.ResponseWriter, r *http.Request) (int,
jis, ok := ji.(*jiraServerInstance)
if !ok {
return http.StatusInternalServerError,
errors.New("Must be a JIRA Server instance, is " + ji.GetType())
errors.New("Must be a Jira Server instance, is " + ji.GetType())
}

requestToken, verifier, err := oauth1.ParseAuthorizationCallback(r)
if err != nil {
return http.StatusInternalServerError,
errors.WithMessage(err, "failed to parse callback request from JIRA")
errors.WithMessage(err, "failed to parse callback request from Jira")
}

requestSecret, err := p.LoadOneTimeSecret(requestToken)
Expand Down
2 changes: 1 addition & 1 deletion server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (p *Plugin) CreateBotDMPost(userId, message, postType string) (returnErr er
func (p *Plugin) loadJIRAProjectKeys(jiraClient *jira.Client) ([]string, error) {
list, _, err := jiraClient.Project.GetList()
if err != nil {
return nil, errors.WithMessage(err, "Error requesting list of JIRA projects")
return nil, errors.WithMessage(err, "Error requesting list of Jira projects")
}

projectKeys := []string{}
Expand Down
2 changes: 1 addition & 1 deletion server/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func httpWebhook(p *Plugin, w http.ResponseWriter, r *http.Request) (int, error)
// TODO add JWT support
cfg := p.getConfig()
if cfg.Secret == "" || cfg.UserName == "" {
return http.StatusForbidden, fmt.Errorf("JIRA plugin not configured correctly; must provide Secret and UserName")
return http.StatusForbidden, fmt.Errorf("Jira plugin not configured correctly; must provide Secret and UserName")
}

err := r.ParseForm()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export default class CreateIssuePostMenuAction extends PureComponent {
role='menuitem'
onClick={this.connectClick}
>
{'Connect to JIRA'}
{'Connect to Jira'}
</button>
);
}
Expand Down