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

[MI-1931] Add API to get projects and get tasks #3

Merged
merged 30 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
3a82837
[MI-1846]: Added nvmrc file
avas27JTG Jun 1, 2022
fe5b450
Modular folder structure
avas27JTG Jun 5, 2022
a87e1b8
Modular folder structure
avas27JTG Jun 5, 2022
7a74d92
[MI-1846]: Base setup
avas27JTG Jun 6, 2022
80a125d
[MI-1846]: Refactored server base setup
avas27JTG Jun 29, 2022
cf35f6f
[MI-1854]: Implement OAuth to access Azure DevOps services
avas27JTG Jul 12, 2022
b5d216b
[MI-1931] Add API to get projects and get tasks
ayusht2810 Jul 13, 2022
5f9a075
[MI-1931] Self review fixes
ayusht2810 Jul 14, 2022
d5682c3
[MI-1931] Review fixes 1
ayusht2810 Jul 15, 2022
d167803
[MI-1931] Self review fix
ayusht2810 Jul 15, 2022
971e0a5
[MI-1846]: Review fixes
avas27JTG Jul 15, 2022
4ffffbd
[MI-1931] Review fixes 2
ayusht2810 Jul 15, 2022
30cc3f1
[MI-1931] Add json error handling
ayusht2810 Jul 15, 2022
49aaa96
[MI-1931] Add comment to the code
ayusht2810 Jul 18, 2022
61e99db
[MI-1931] Add error check
ayusht2810 Jul 20, 2022
7db4e3c
[MI-1846]: Review fixes
avas27JTG Jul 22, 2022
21ff45b
Merge branch 'MI-1846' of github.com:Brightscout/mattermost-plugin-az…
avas27JTG Jul 22, 2022
1313fcc
[MI-1854]: Review fixes
avas27JTG Jul 22, 2022
7fd2e97
[MI-1854]: Removed unused config
avas27JTG Jul 22, 2022
c5ef16e
[MI-1854]: Added logic to verify state
avas27JTG Jul 25, 2022
1f7fc44
[MI-1931] Pull from parent [MI-1854_1]
ayusht2810 Jul 25, 2022
c6b2e7c
[MI-1931] Run fmt
ayusht2810 Jul 25, 2022
a0f77a6
[MI-1854]: Removed unused configs
avas27JTG Jul 26, 2022
d45ea73
Merge branch 'master' of github.com:Brightscout/mattermost-plugin-azu…
avas27JTG Jul 26, 2022
58faba5
[MI-1854]: Review fixes
avas27JTG Jul 27, 2022
d9eab3b
[MI-1931] Pull from parent [MI-1854_1]
ayusht2810 Jul 27, 2022
000e9df
[MI-1931] Pull from master
ayusht2810 Jul 28, 2022
cee16dc
[MI-1931] Remove unused code
ayusht2810 Jul 29, 2022
217f50e
[MI-1931] Correct spelling error
ayusht2810 Jul 29, 2022
39cbe06
[MI-1931] Correct formatting
ayusht2810 Aug 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/azurebot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
406 changes: 406 additions & 0 deletions assets/azurebot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 0 additions & 14 deletions assets/starter-template-icon.svg

This file was deleted.

2 changes: 1 addition & 1 deletion build/manifest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v5/model"
"github.com/pkg/errors"
)

Expand Down
2 changes: 1 addition & 1 deletion build/pluginctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"net"
"os"

"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v5/model"
)

const helpText = `
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module github.com/mattermost/mattermost-plugin-starter-template
module github.com/Brightscout/mattermost-plugin-azure-devops

go 1.16

require (
github.com/mattermost/mattermost-server/v6 v6.2.1
github.com/gorilla/mux v1.8.0
github.com/mattermost/mattermost-plugin-api v0.0.27
github.com/mattermost/mattermost-server/v5 v5.37.9
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
)
905 changes: 795 additions & 110 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"encoding/json"
"strings"

"github.com/mattermost/mattermost-server/v6/model"
"github.com/mattermost/mattermost-server/v5/model"
)

//go:embed plugin.json
Expand Down
62 changes: 57 additions & 5 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"id": "com.mattermost.plugin-starter-template",
"name": "Plugin Starter Template",
"description": "This plugin serves as a starting point for writing a Mattermost plugin.",
"id": "mattermost-plugin-azure-devops",
"name": "Mattermost Azure Devops plugin",
"description": "This plugin provides services of Azure DevOps such as Boards, Repos and Pipelines",
"homepage_url": "https://github.com/mattermost/mattermost-plugin-starter-template",
"support_url": "https://github.com/mattermost/mattermost-plugin-starter-template/issues",
"release_notes_url": "https://github.com/mattermost/mattermost-plugin-starter-template/releases/tag/v0.1.0",
"icon_path": "assets/starter-template-icon.svg",
"icon_path": "assets/azurebot.svg",
"version": "0.1.0",
"min_server_version": "5.37.0",
"server": {
Expand All @@ -23,6 +23,58 @@
"settings_schema": {
"header": "",
"footer": "",
"settings": []
"settings": [
{
"key": "azureDevopsAPIBaseURL",
"display_name": "Azure Devops API base URL",
"type": "text",
"help_text": "Enter the base URL for Azure Devops API"
},
{
"key": "azureDevopsOAuthAppID",
"display_name": "Azure Devops OAuth App ID",
"type": "text",
"help_text": "Enter the app ID for the OAuth app registered with Azure Devops"
},
{
"key": "azureDevopsOAuthClientSecret",
"display_name": "Azure Devops OAuth Client Secret",
"type": "text",
"help_text": "Enter the client secret for the OAuth app registered with Azure Devops.",
"placeholder": "",
"default": null
},
{
"key": "azureDevopsOAuthAuthorizationURL",
"display_name": "Azure Devops OAuth Authorization URL",
"type": "text",
"help_text": "Enter the authorization URL for the OAuth app registered with Azure Devops.",
"placeholder": "",
"default": "https://app.vssps.visualstudio.com/oauth2/authorize"
},
{
"key": "azureDevopsOAuthTokenURL",
"display_name": "Azure Devops OAuth Access Token URL",
"type": "text",
"help_text": "Enter the access token URL for the OAuth app registered with Azure Devops.",
"placeholder": "",
"default": "https://app.vssps.visualstudio.com/oauth2/token"
},
{
"key": "azureDevopsOAuthCallbackURL",
"display_name": "Azure Devops OAuth callback URL",
"type": "text",
"help_text": "Enter the callback URL for the OAuth app registered with Azure Devops.",
"placeholder": "",
"default": null
},
{
"key": "EncryptionSecret",
"display_name": "Encryption Secret:",
"type": "generated",
"help_text": "The secret key used to encrypt and decrpyt OAuth token.",
"default": null
}
]
}
}
78 changes: 78 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package config

import (
"errors"
"strings"
)

// Configuration captures the plugin's external configuration as exposed in the Mattermost server
// configuration, as well as values computed from the configuration. Any public fields will be
// deserialized from the Mattermost server configuration in OnConfigurationChange.
//
// As plugins are inherently concurrent (hooks being called asynchronously), and the plugin
// configuration can change at any time, access to the configuration must be synchronized. The
// strategy used in this plugin is to guard a pointer to the configuration, and clone the entire
// struct whenever it changes. You may replace this with whatever strategy you choose.
//
// If you add non-reference types to your configuration struct, be sure to rewrite Clone as a deep
// copy appropriate for your types.
type Configuration struct {
// TODO: Below configs are not final they are used as placeholder here
AzureDevopsAPIBaseURL string `json:"azureDevopsAPIBaseURL"`
AzureDevopsOAuthAppID string `json:"azureDevopsOAuthAppID"`
AzureDevopsOAuthClientSecret string `jso:"azureDevopsOAuthClientSecret"`
AzureDevopsOAuthAuthorizationURL string `json:"azureDevopsOAuthAuthorizationURL"`
AzureDevopsOAuthTokenURL string `json:"azureDevopsOAuthTokenURL"`
AzureDevopsOAuthCallbackURL string `json:"azureDevopsOAuthCallbackURL"`
EncryptionSecret string `json:"EncryptionSecret"`
MattermostSiteURL string
PluginID string
PluginURL string
PluginURLPath string
}

// Clone shallow copies the configuration. Your implementation may require a deep copy if
// your configuration has reference types.
func (c *Configuration) Clone() *Configuration {
var clone = *c
return &clone
}

// Used for post-processing on the configuration.
func (c *Configuration) ProcessConfiguration() error {
c.AzureDevopsAPIBaseURL = strings.TrimRight(strings.TrimSpace(c.AzureDevopsAPIBaseURL), "/")
c.AzureDevopsOAuthAppID = strings.TrimSpace(c.AzureDevopsOAuthAppID)
c.AzureDevopsOAuthClientSecret = strings.TrimSpace(c.AzureDevopsOAuthClientSecret)
c.AzureDevopsOAuthAuthorizationURL = strings.TrimRight(strings.TrimSpace(c.AzureDevopsOAuthAuthorizationURL), "/")
c.AzureDevopsOAuthTokenURL = strings.TrimRight(strings.TrimSpace(c.AzureDevopsOAuthTokenURL), "/")
c.EncryptionSecret = strings.TrimSpace(c.EncryptionSecret)

return nil
}

// Used for config validations.
func (c *Configuration) IsValid() error {
if c.AzureDevopsAPIBaseURL == "" {
return errors.New("azure devops API base URL should not be empty")
}
if c.AzureDevopsOAuthAppID == "" {
return errors.New("azure devops OAuth app id should not be empty")
}
if c.AzureDevopsOAuthClientSecret == "" {
return errors.New("azure devops OAuth client secret should not be empty")
}
if c.AzureDevopsOAuthAuthorizationURL == "" {
return errors.New("azure devops OAuth authorization URL should not be empty")
}
if c.AzureDevopsOAuthTokenURL == "" {
return errors.New("azure devops OAuth token URL should not be empty")
}
if c.AzureDevopsOAuthCallbackURL == "" {
return errors.New("azure devops OAuth callback URL should not be empty")
}
if c.EncryptionSecret == "" {
return errors.New("encryption secret should not be empty")
}

return nil
}
83 changes: 0 additions & 83 deletions server/configuration.go

This file was deleted.

64 changes: 64 additions & 0 deletions server/constants/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package constants

const (
// Bot configs
BotUsername = "azuredevops"
BotDisplayName = "Azure Devops Plugin"
BotDescription = "A bot account created by the Azure Devops plugin."

// Plugin configs
PluginID = "mattermost-plugin-azure-devops"
HeaderMattermostUserID = "User-ID"
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved

// Command configs
CommandTriggerName = "azuredevops"
HelpText = "###### Mattermost Azure Devops Plugin - Slash Command Help\n"
InvalidCommand = "Invalid command parameters. Please use `/azuredevops help` for more information."

// Plugin API Routes
APIPrefix = "/api/v1"
WildRoute = "{anything:.*}"
PathOAuthConnect = "/connect"
PathOAuthCallback = "/callback"

// Azure API Routes
// GetProjects = "/%s/_apis/projects"
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved
GetTasksID = "/%s/_apis/wit/wiql"
GetTasks = "/%s/_apis/wit/workitems"

// Azure API versions
// ProjectAPIVersion = "7.1-preview.4"
TasksIDAPIVersion = "5.1"
TasksAPIVersion = "6.0"

// Authorization constants
Bearer = "Bearer %s"
manojmalik20 marked this conversation as resolved.
Show resolved Hide resolved
Authorization = "Authorization"

// Max tasks and projects per page
ayusht2810 marked this conversation as resolved.
Show resolved Hide resolved
// ProjectLimit = 10
TaskLimit = 10

// Query params constants
PageQueryParam = "$top"
APIVersionQueryParam = "api-version"
IDsQueryParam = "ids"

// Generic messages
// TODO: all these messages are to be verified from Mike at the end
ConnectAccount = "[Click here to link your Azure DevOps account](%s%s?channel_id=%s)"
ConnectAccountFirst = "You do not have any Azure Devops account connected, kindly link the account first"
UserConnected = "Your Azure Devops account is succesfully connected!"
UserAlreadyConnected = "Your Azure Devops account is already connected"
UserDisconnected = "Your Azure Devops account is now disconnected"

// Error messages
GenericErrorMessage = "something went wrong, please try again later"
NotAuthorized = "not authorized"
InvalidPageNumber = "invalid page number"
OrganizationRequired = "organization is required"
ProjectRequired = "project is required"
InvalidStatus = "invalid status"
InvalidAssignedTo = "you can only see tasks assigned to yourself"
NoResultPresent = "no results are present"
)
8 changes: 8 additions & 0 deletions server/constants/oAuth_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package constants

const (
ResponseType = "Assertion"
Scopes = "vso.code vso.work_full"
ClientAssertionType = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
GrantType = "urn:ietf:params:oauth:grant-type:jwt-bearer"
)
8 changes: 8 additions & 0 deletions server/constants/taskQuery.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package constants

const (
// TaskQuery
TaskQuery = "Select [System.Id] From WorkItems Where [System.TeamProject] = '%s'"
TaskQueryStatusFilter = " and [System.State] = '%s'"
TaskQueryAssignedToFilter = " and [System.AssignedTo] = @me"
)
6 changes: 4 additions & 2 deletions server/main.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package main

import (
"github.com/mattermost/mattermost-server/v6/plugin"
mattermostPlugin "github.com/mattermost/mattermost-server/v5/plugin"

"github.com/Brightscout/mattermost-plugin-azure-devops/server/plugin"
)

func main() {
plugin.ClientMain(&Plugin{})
mattermostPlugin.ClientMain(&plugin.Plugin{})
}
Loading