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-2360] Updated APIs to create/delete subscriptions and subscription card for "Build" and "Release" events #110

Merged
merged 63 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
69fb0fe
[MI-2258]: [server]: Create plugin API to request Azure DevOps and fe…
avas27JTG Oct 17, 2022
71811e0
[MI-2258][server][review_fix][CI_fix]: review fixes and added mock me…
avas27JTG Oct 20, 2022
1784b48
[MI-2279][webapp]: Created UI and integrated repository filter for Repos
avas27JTG Oct 20, 2022
d268fa3
[MI-2279][webapp]: Fixed util
avas27JTG Oct 20, 2022
336cc74
[MI-2279][webapp]: Enhanced UX
avas27JTG Oct 20, 2022
de9efc1
[MI-2262][server]: Created plugin API to request branches for a repo.
avas27JTG Oct 20, 2022
b6e744e
Merge branch 'MI-2258' of github.com:Brightscout/mattermost-plugin-az…
avas27JTG Oct 20, 2022
a07cd3f
Merge branch 'MI-2258' of github.com:Brightscout/mattermost-plugin-az…
avas27JTG Oct 20, 2022
91003e3
Merge branch 'MI-2279' of github.com:Brightscout/mattermost-plugin-az…
avas27JTG Oct 20, 2022
839f0a6
[MI-2262][server]: Added mocked client method
avas27JTG Oct 20, 2022
fac6180
WIP
avas27JTG Oct 21, 2022
adba9b8
[MI-2284][server+webapp]: Made server changes to add filters as uniqu…
avas27JTG Oct 21, 2022
6e5af50
[server+webapp]: Differentiated payload for service-type and Created …
avas27JTG Oct 25, 2022
0adf21c
[MI-2288][server+webapp]: Changed struct type for publisher inputs
avas27JTG Oct 25, 2022
bb10f55
[MI-2288][server+webapp]: Modified projectID field name
avas27JTG Oct 25, 2022
0946156
[MI-2288][webapp]: Added tolltip on chip
avas27JTG Oct 26, 2022
314936a
[MI-2288][webapp]: Fixed import order
avas27JTG Oct 26, 2022
6f3fb7b
[MI-2294][server]: Created plugin API to fetch possible values for su…
avas27JTG Oct 27, 2022
f03ee56
[MI-2294][server]: Added mocked client function
avas27JTG Oct 27, 2022
a36b34b
[MI-2294][server]: Fixed golint error
avas27JTG Oct 27, 2022
19a1728
[MI-2314][server+webapp]: Made changes in plugin API for returning fi…
avas27JTG Nov 1, 2022
9c40222
Merge branch 'master' of github.com:Brightscout/mattermost-plugin-azu…
avas27JTG Nov 1, 2022
ad33636
merge changes synced
avas27JTG Nov 1, 2022
74c4aa7
Merge branch 'MI-2294' of github.com:Brightscout/mattermost-plugin-az…
avas27JTG Nov 1, 2022
da088ca
[MI-2314][server+Webapp]: Implemented conditional filters for Repos a…
avas27JTG Nov 3, 2022
5370025
[MI-2294][server][review_fix]: Minor refactoring
avas27JTG Nov 8, 2022
fd992e4
[MI-2294][server][review_fix]: Reverted extra line removal
avas27JTG Nov 8, 2022
59eb0ae
[MI-2294][server][review_fix]: used constants and added server log
avas27JTG Nov 8, 2022
3d509dd
[MI-2294][server]: Removed extra mock methods
avas27JTG Nov 8, 2022
c5d17fb
[MI-2314][webapp]: Refactoring
avas27JTG Nov 8, 2022
6c2d576
[MI-2314][webapp]: Refactoring
avas27JTG Nov 8, 2022
1b47f6b
Merge branch 'MI-2294' of github.com:Brightscout/mattermost-plugin-az…
avas27JTG Nov 8, 2022
89b45ac
[MI-2314][MI-2287] Fixed failing testcases
raghavaggarwal2308 Nov 8, 2022
737bc80
[MI-2314][webapp]: Exported constant variables
avas27JTG Nov 9, 2022
e878063
[MI-2339][server]: Added support to show pipeline build link preview.
avas27JTG Nov 9, 2022
23f45e4
[MI-2339][server]: Added mock method for pipeline build
avas27JTG Nov 9, 2022
9a6c316
Merge branch 'MI-2314' of github.com:Brightscout/mattermost-plugin-az…
raghavaggarwal2308 Nov 9, 2022
8963751
[MI-2339][server]: Updated error message
avas27JTG Nov 9, 2022
67fa2ae
[MI-2341][webapp+server] Added filters for "Build" and "Release" events
raghavaggarwal2308 Nov 16, 2022
760c6c6
Merge branch 'epic_phase_3' of github.com:Brightscout/mattermost-plug…
raghavaggarwal2308 Nov 16, 2022
e2b97bc
[MI-2341] Changed name of struct field 'ReleaseDefinitionID : Release…
raghavaggarwal2308 Nov 17, 2022
05caef6
Merge branch 'MI-2315' of github.com:Brightscout/mattermost-plugin-az…
avas27JTG Nov 17, 2022
6e870e8
[MI-2339][server][review_fix]: Minor refactoring
avas27JTG Nov 17, 2022
a1428bd
Merge branch 'MI-2339' of github.com:Brightscout/mattermost-plugin-az…
raghavaggarwal2308 Nov 18, 2022
9ef8073
[MI-2360] Updated "CreateSubscription" API and subscription card acco…
raghavaggarwal2308 Nov 18, 2022
393434d
[MI-2360] Fixed failing testcases
raghavaggarwal2308 Nov 21, 2022
1e02f0a
[MI-2360] Removed redundant code
raghavaggarwal2308 Nov 24, 2022
bd7a3dd
[MI-2360] Removed unused code and updated mock_client
raghavaggarwal2308 Nov 24, 2022
c50537f
[MI-2341] Review fixes
raghavaggarwal2308 Nov 28, 2022
3431efb
[MI-2339][server][review_fix]: Added debug logs and changed casings
avas27JTG Nov 30, 2022
c9b6513
[MI-2341] Review fix
raghavaggarwal2308 Nov 30, 2022
8376f4f
[MI-2360] Minor fix
raghavaggarwal2308 Nov 30, 2022
fd3d2d2
Merge branch 'epic_phase_3' of github.com:Brightscout/mattermost-plug…
avas27JTG Nov 30, 2022
d9faef2
[MI-2339][server]: Changed pipeline icon name
avas27JTG Nov 30, 2022
3bbb0d5
[MI_2360] Changed name of struct fields
raghavaggarwal2308 Dec 1, 2022
1071ba6
Merge branch 'epic_phase_3' of github.com:mattermost/mattermost-plugi…
raghavaggarwal2308 Dec 5, 2022
ed9e869
Merge branch 'MI-2339' of github.com:mattermost/mattermost-plugin-azu…
raghavaggarwal2308 Dec 5, 2022
a5c737c
Merge branch 'MI-2341' of github.com:mattermost/mattermost-plugin-azu…
raghavaggarwal2308 Dec 5, 2022
7ce5c5b
[MI-2341] Review fixes
raghavaggarwal2308 Dec 19, 2022
8d40948
Merge branch 'epic_phase_3' of github.com:mattermost/mattermost-plugi…
raghavaggarwal2308 Dec 19, 2022
09355c6
Merge branch 'MI-2341' of github.com:mattermost/mattermost-plugin-azu…
raghavaggarwal2308 Dec 19, 2022
d9ac1b7
[MI-2360] Generated MD5 hash for subscription key
raghavaggarwal2308 Dec 19, 2022
8449b17
Merge branch 'epic_phase_3' of github.com:mattermost/mattermost-plugi…
raghavaggarwal2308 Dec 19, 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
7 changes: 7 additions & 0 deletions assets/pipeline-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions mocks/mock_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 43 additions & 22 deletions server/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
CommandLink = "link"
CommandBoards = "boards"
CommandRepos = "repos"
CommandPipelines = "pipelines"
CommandCreate = "create"
CommandSubscription = "subscription"
CommandAdd = "add"
Expand All @@ -40,24 +41,38 @@ const (
// Regex to verify pull request link
PullRequestLinkRegex = `http(s)?:\/\/dev.azure.com\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/_git\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/pullrequest\/[1-9]+`

// Regex to verify pipeline build details link
BuildDetailsLinkRegex = `http(s)?:\/\/dev.azure.com\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]*\/_build\/results\?buildId=[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+`

// Azure API Versions
CreateTaskAPIVersion = "7.1-preview.3"
TasksIDAPIVersion = "5.1"
TasksAPIVersion = "6.0"

// Subscription constants
PublisherID = "tfs"
ConsumerID = "webHooks"
ConsumerActionID = "httpRequest"
SubscriptionEventPullRequestCreated = "git.pullrequest.created"
SubscriptionEventPullRequestUpdated = "git.pullrequest.updated"
SubscriptionEventPullRequestCommented = "ms.vss-code.git-pullrequest-comment-event"
SubscriptionEventPullRequestMerged = "git.pullrequest.merged"
SubscriptionEventCodePushed = "git.push"
SubscriptionEventWorkItemCreated = "workitem.created"
SubscriptionEventWorkItemUpdated = "workitem.updated"
SubscriptionEventWorkItemDeleted = "workitem.deleted"
SubscriptionEventWorkItemCommented = "workitem.commented"
PublisherID = "tfs"
ConsumerID = "webHooks"
ConsumerActionID = "httpRequest"
SubscriptionEventPullRequestCreated = "git.pullrequest.created"
SubscriptionEventPullRequestUpdated = "git.pullrequest.updated"
SubscriptionEventPullRequestCommented = "ms.vss-code.git-pullrequest-comment-event"
SubscriptionEventPullRequestMerged = "git.pullrequest.merged"
SubscriptionEventCodePushed = "git.push"
SubscriptionEventWorkItemCreated = "workitem.created"
SubscriptionEventWorkItemUpdated = "workitem.updated"
SubscriptionEventWorkItemDeleted = "workitem.deleted"
SubscriptionEventWorkItemCommented = "workitem.commented"
SubscriptionEventBuildCompleted = "build.complete"
SubscriptionEventReleaseAbandoned = "ms.vss-release.release-abandoned-event"
SubscriptionEventReleaseCreated = "ms.vss-release.release-created-event"
SubscriptionEventReleaseDeploymentApprovalCompleted = "ms.vss-release.deployment-approval-completed-event"
SubscriptionEventReleaseDeploymentEventPending = "ms.vss-release.deployment-approval-pending-event"
SubscriptionEventReleaseDeploymentCompleted = "ms.vss-release.deployment-completed-event"
SubscriptionEventReleaseDeploymentStarted = "ms.vss-release.deployment-started-event"
SubscriptionEventRunStageApprovalCompleted = "ms.vss-pipelinechecks-events.approval-completed"
SubscriptionEventRunStageStateChanged = "ms.vss-pipelines.stage-state-changed-event"
SubscriptionEventRunStageWaitingForApproval = "ms.vss-pipelinechecks-events.approval-pending"
SubscriptionEventRunStateChanged = "ms.vss-pipelines.run-state-changed-event"

// Path params
PathParamTeamID = "team_id"
Expand All @@ -75,12 +90,15 @@ const (
QueryParamPerPage = "per_page"

// Filters
FilterCreatedByMe = "me"
FilterCreatedByAnyone = "anyone"
FilterAllChannels = "all_channels"
FilterAll = "all"
FilterBoards = "boards"
FilterRepos = "repos"
FilterCreatedByMe = "me"
FilterCreatedByAnyone = "anyone"
FilterAllChannels = "all_channels"
FilterAll = "all"
FilterBoards = "boards"
FilterRepos = "repos"
EventTypeRelease = "release"
FilterIDReleaseDefinitionID = "releaseDefinitionId"
FilterIDReleaseEnvironmentID = "releaseEnvironmentId"

DefaultPage = 0
DefaultPerPageLimit = 50
Expand All @@ -103,22 +121,25 @@ const (
WSEventSubscriptionDeleted = "subscription_deleted"

// Colors
ReposIconColor = "#d74f27"
BoardsIconColor = "#53bba1"
ReposIconColor = "#d74f27"
BoardsIconColor = "#53bba1"
PipelineIconColor = "#4275E4"

SubscriptionEventTypeDummy = "dummy"
FileNameGitBranchIcon = "git-branch-icon.svg"
FileNameProjectIcon = "project-icon.svg"
FileNameReposIcon = "repos-icon.svg"
FileNameBoardsIcon = "boards-icon.svg"
FileNamePipeline = "pipeline-icon.svg"
IconColorBoards = "#53bba1"
IconColorRepos = "#d74f27"

SlackAttachmentAuthorNameRepos = "Azure Repos"
SlackAttachmentAuthorNameBoards = "Azure Boards"

ServiceTypeBoards = "boards"
ServiceTypeRepos = "repos"
ServiceTypeBoards = "boards"
ServiceTypeRepos = "repos"
ServiceTypePipelines = "pipelines"
)

var (
Expand Down
1 change: 1 addition & 0 deletions server/constants/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
CreatedTask = "[%s #%d](%s) (%s) was successfully created by %s."
TaskTitle = "[%s #%d: %s](%s)"
PullRequestTitle = "[#%d: %s](%s)"
BuildDetailsTitle = "[#%s](%s): %s"
AlreadyLinkedProject = "This project is already linked."
NoProjectLinked = "No project is linked, please link a project."

Expand Down
2 changes: 1 addition & 1 deletion server/constants/oauth_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package constants

const (
ResponseType = "Assertion"
Scopes = "vso.code_full vso.work_full"
Scopes = "vso.build_execute vso.code_full vso.release_manage vso.work_full"
ClientAssertionType = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
GrantType = "urn:ietf:params:oauth:grant-type:jwt-bearer"
GrantTypeRefresh = "refresh_token"
Expand Down
5 changes: 2 additions & 3 deletions server/constants/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@ const (
PathGetSubscriptions = "/subscriptions/{team_id:[A-Za-z0-9]+}"
PathSubscriptionNotifications = "/notification"
PathGetUserChannelsForTeam = "/channels/{team_id:[A-Za-z0-9]+}"
PathGetGitRepositories = "/{organization:[A-Za-z0-9-/ ]+}/{project:[A-Za-z0-9-/ ]+}/repositories"
PathGetGitRepositoryBranches = "/{organization:[A-Za-z0-9-/ ]+}/{project:[A-Za-z0-9-/ ]+}/repositories/{repository:[A-Za-z0-9-/]+}/branches"
PathGetSubscriptionFilterPossibleValues = "/subscriptions/filters"

// Azure API paths
CreateTask = "/%s/%s/_apis/wit/workitems/$%s?api-version=7.1-preview.3"
GetTask = "%s/%s/_apis/wit/workitems/%s?api-version=7.1-preview.3"
GetPullRequest = "%s/%s/_apis/git/pullrequests/%s?api-version=6.0"
GetBuildDetails = "%s/%s/_apis/build/builds/%s?api-version=6.0"
GetGitRepositories = "%s/%s/_apis/git/repositories?api-version=6.0"
GetGitRepositoryBranches = "%s/%s/_apis/git/repositories/%s/refs?filter=heads"
GetSubscriptionFilterPossibleValues = "%s/_apis/hooks/inputValuesQuery?api-version=6.0"
GetProject = "/%s/_apis/projects/%s?api-version=7.1-preview.4"
CreateSubscription = "/%s/_apis/hooks/subscriptions?api-version=6.0"
DeleteSubscription = "/%s/_apis/hooks/subscriptions/%s?api-version=6.0"
GetSubscriptionFilterPossibleValues = "%s/_apis/hooks/inputValuesQuery?api-version=6.0"
)
108 changes: 50 additions & 58 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ func (p *Plugin) InitRoutes() {
s.HandleFunc(constants.PathSubscriptionNotifications, p.handleSubscriptionNotifications).Methods(http.MethodPost)
s.HandleFunc(constants.PathSubscriptions, p.handleAuthRequired(p.checkOAuth(p.handleDeleteSubscriptions))).Methods(http.MethodDelete)
s.HandleFunc(constants.PathGetUserChannelsForTeam, p.handleAuthRequired(p.getUserChannelsForTeam)).Methods(http.MethodGet)
s.HandleFunc(constants.PathGetGitRepositories, p.handleAuthRequired(p.checkOAuth(p.handleGetGitRepositories))).Methods(http.MethodGet)
s.HandleFunc(constants.PathGetGitRepositoryBranches, p.handleAuthRequired(p.checkOAuth(p.handleGetGitRepositoryBranches))).Methods(http.MethodGet)
s.HandleFunc(constants.PathGetSubscriptionFilterPossibleValues, p.handleAuthRequired(p.checkOAuth(p.handleGetSubscriptionFilterPossibleValues))).Methods(http.MethodPost)
}

Expand Down Expand Up @@ -268,6 +266,13 @@ func (p *Plugin) handleCreateSubscription(w http.ResponseWriter, r *http.Request
MergeResult: body.MergeResult,
NotificationType: body.NotificationType,
AreaPath: body.AreaPath,
BuildStatus: body.BuildStatus,
BuildPipeline: body.BuildPipeline,
StageName: body.StageName,
ReleasePipeline: body.ReleasePipeline,
ReleaseStatus: body.ReleaseStatus,
ApprovalType: body.ApprovalType,
ApprovalStatus: body.ApprovalStatus,
}); isSubscriptionPresent {
p.API.LogError(constants.SubscriptionAlreadyPresent, "Error")
p.handleError(w, r, &serializers.Error{Code: http.StatusBadRequest, Message: constants.SubscriptionAlreadyPresent})
Expand Down Expand Up @@ -325,6 +330,19 @@ func (p *Plugin) handleCreateSubscription(w http.ResponseWriter, r *http.Request
NotificationType: body.NotificationType,
NotificationTypeName: body.NotificationTypeName,
AreaPath: body.AreaPath,
BuildStatus: body.BuildStatus,
BuildPipeline: body.BuildPipeline,
StageName: body.StageName,
ReleasePipeline: body.ReleasePipeline,
ReleaseStatus: body.ReleaseStatus,
ApprovalType: body.ApprovalType,
ApprovalStatus: body.ApprovalStatus,
BuildStatusName: body.BuildStatusName,
StageNameValue: body.StageNameValue,
ReleasePipelineName: body.ReleasePipelineName,
ReleaseStatusName: body.ReleaseStatusName,
ApprovalTypeName: body.ApprovalTypeName,
ApprovalStatusName: body.ApprovalStatusName,
}); storeErr != nil {
p.API.LogError("Error in creating a subscription", "Error", storeErr.Error())
p.handleError(w, r, &serializers.Error{Code: http.StatusInternalServerError, Message: storeErr.Error()})
Expand Down Expand Up @@ -408,7 +426,14 @@ func (p *Plugin) handleGetSubscriptions(w http.ResponseWriter, r *http.Request)
subscriptionByProject[i].PushedByName+
subscriptionByProject[i].MergeResultName+
subscriptionByProject[i].NotificationTypeName+
subscriptionByProject[i].AreaPath <
subscriptionByProject[i].AreaPath+
subscriptionByProject[i].ReleasePipelineName+
subscriptionByProject[i].BuildPipeline+
subscriptionByProject[i].BuildStatusName+
subscriptionByProject[i].ApprovalStatusName+
subscriptionByProject[i].ApprovalTypeName+
subscriptionByProject[i].StageNameValue+
subscriptionByProject[i].ReleaseStatusName <
subscriptionByProject[j].ChannelName+
subscriptionByProject[j].EventType+
subscriptionByProject[j].TargetBranch+
Expand All @@ -417,7 +442,14 @@ func (p *Plugin) handleGetSubscriptions(w http.ResponseWriter, r *http.Request)
subscriptionByProject[j].PushedByName+
subscriptionByProject[j].MergeResultName+
subscriptionByProject[j].NotificationTypeName+
subscriptionByProject[j].AreaPath
subscriptionByProject[j].AreaPath+
subscriptionByProject[i].ReleasePipelineName+
subscriptionByProject[i].BuildPipeline+
subscriptionByProject[i].BuildStatusName+
subscriptionByProject[i].ApprovalStatusName+
subscriptionByProject[i].ApprovalTypeName+
subscriptionByProject[i].StageNameValue+
subscriptionByProject[i].ReleaseStatusName
})

filteredSubscriptionList, filteredSubscriptionErr := p.GetSubscriptionsForAccessibleChannelsOrProjects(subscriptionByProject, teamID, mattermostUserID)
Expand Down Expand Up @@ -637,6 +669,13 @@ func (p *Plugin) handleDeleteSubscriptions(w http.ResponseWriter, r *http.Reques
MergeResult: body.MergeResult,
NotificationType: body.NotificationType,
AreaPath: body.AreaPath,
BuildStatus: body.BuildStatus,
BuildPipeline: body.BuildPipeline,
StageName: body.StageName,
ReleasePipeline: body.ReleasePipeline,
ReleaseStatus: body.ReleaseStatus,
ApprovalType: body.ApprovalType,
ApprovalStatus: body.ApprovalStatus,
})
if !isSubscriptionPresent {
p.API.LogError(constants.SubscriptionNotFound)
Expand Down Expand Up @@ -664,6 +703,13 @@ func (p *Plugin) handleDeleteSubscriptions(w http.ResponseWriter, r *http.Reques
MergeResult: body.MergeResult,
NotificationType: body.NotificationType,
AreaPath: body.AreaPath,
BuildStatus: body.BuildStatus,
BuildPipeline: body.BuildPipeline,
StageName: body.StageName,
ReleasePipeline: body.ReleasePipeline,
ReleaseStatus: body.ReleaseStatus,
ApprovalType: body.ApprovalType,
ApprovalStatus: body.ApprovalStatus,
}); deleteErr != nil {
p.API.LogError(constants.DeleteSubscriptionError, "Error", deleteErr.Error())
p.handleError(w, r, &serializers.Error{Code: http.StatusInternalServerError, Message: deleteErr.Error()})
Expand Down Expand Up @@ -787,60 +833,6 @@ func (p *Plugin) handleGetUserAccountDetails(w http.ResponseWriter, r *http.Requ
p.writeJSON(w, &userDetails)
}

func (p *Plugin) handleGetGitRepositories(w http.ResponseWriter, r *http.Request) {
mattermostUserID := r.Header.Get(constants.HeaderMattermostUserID)

pathParams := mux.Vars(r)
organization := pathParams[constants.PathParamOrganization]
project := pathParams[constants.PathParamProject]

if len(strings.TrimSpace(organization)) == 0 || len(strings.TrimSpace(project)) == 0 {
p.API.LogError(constants.ErrorOrganizationOrProjectQueryParam)
p.handleError(w, r, &serializers.Error{Code: http.StatusBadRequest, Message: constants.ErrorOrganizationOrProjectQueryParam})
return
}

response, statusCode, err := p.Client.GetGitRepositories(organization, project, mattermostUserID)
raghavaggarwal2308 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
p.API.LogError("Error in fetching git repositories", err.Error())
p.handleError(w, r, &serializers.Error{Code: statusCode, Message: err.Error()})
return
}

p.writeJSON(w, response.Value)
}

func (p *Plugin) handleGetGitRepositoryBranches(w http.ResponseWriter, r *http.Request) {
mattermostUserID := r.Header.Get(constants.HeaderMattermostUserID)

pathParams := mux.Vars(r)
organization := strings.TrimSpace(pathParams[constants.PathParamOrganization])
project := strings.TrimSpace(pathParams[constants.PathParamProject])
repository := strings.TrimSpace(pathParams[constants.PathParamRepository])

if len(organization) == 0 || len(project) == 0 || len(repository) == 0 {
p.API.LogError(constants.ErrorRepositoryPathParam)
p.handleError(w, r, &serializers.Error{Code: http.StatusBadRequest, Message: constants.ErrorRepositoryPathParam})
return
}

response, statusCode, err := p.Client.GetGitRepositoryBranches(organization, project, repository, mattermostUserID)
raghavaggarwal2308 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
p.API.LogError("Error in fetching git repository branches", err.Error())
p.handleError(w, r, &serializers.Error{Code: statusCode, Message: err.Error()})
return
}

// Azure DevOps returns branch name as "refs/heads/<branch-name>", but we need to use only "<branch-name>" so, remove unused part from the name
for _, value := range response.Value {
if strings.Contains(value.Name, "refs/heads/") && len(value.Name) > 11 {
value.Name = value.Name[11:]
}
}

p.writeJSON(w, response.Value)
}

func (p *Plugin) handleGetSubscriptionFilterPossibleValues(w http.ResponseWriter, r *http.Request) {
mattermostUserID := r.Header.Get(constants.HeaderMattermostUserID)

Expand Down
Loading