add deployment summary endpoints
This commit is contained in:
parent
7680702130
commit
cbeaa0952e
10 changed files with 178 additions and 0 deletions
|
@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Added
|
||||
- endpoint to display the latest build by branch. [#2940](https://github.com/drone/drone/pull/2940).
|
||||
- endpoint to display the latest build by pull request. [#2940](https://github.com/drone/drone/pull/2940).
|
||||
- endpoint to display the latest build by environment. [#2940](https://github.com/drone/drone/pull/2940).
|
||||
- endpoint to delete a branch from the index. [#2940](https://github.com/drone/drone/pull/2940).
|
||||
- endpoint to delete a pull request from the index. [#2940](https://github.com/drone/drone/pull/2940).
|
||||
- endpoint to delete an environment from the index. [#2940](https://github.com/drone/drone/pull/2940).
|
||||
|
||||
### Fixed
|
||||
- do not execute cron job for disabled repositories. [#2931](https://github.com/drone/drone/issues/2931).
|
||||
|
|
|
@ -79,6 +79,10 @@ type BuildStore interface {
|
|||
// datastore by pull requeset.
|
||||
LatestPulls(context.Context, int64) ([]*Build, error)
|
||||
|
||||
// LatestDeploys returns the latest builds from the
|
||||
// datastore by deployment target.
|
||||
LatestDeploys(context.Context, int64) ([]*Build, error)
|
||||
|
||||
// Pending returns a list of pending builds from the
|
||||
// datastore by repository id (DEPRECATED).
|
||||
Pending(context.Context) ([]*Build, error)
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/drone/drone/handler/api/repos"
|
||||
"github.com/drone/drone/handler/api/repos/builds"
|
||||
"github.com/drone/drone/handler/api/repos/builds/branches"
|
||||
"github.com/drone/drone/handler/api/repos/builds/deploys"
|
||||
"github.com/drone/drone/handler/api/repos/builds/logs"
|
||||
"github.com/drone/drone/handler/api/repos/builds/pulls"
|
||||
"github.com/drone/drone/handler/api/repos/builds/stages"
|
||||
|
@ -192,6 +193,9 @@ func (s Server) Handler() http.Handler {
|
|||
r.Get("/pulls", pulls.HandleList(s.Repos, s.Builds))
|
||||
r.With(acl.CheckWriteAccess()).Delete("/pulls/{pull}", pulls.HandleDelete(s.Repos, s.Builds))
|
||||
|
||||
r.Get("/deployments", deploys.HandleList(s.Repos, s.Builds))
|
||||
r.With(acl.CheckWriteAccess()).Delete("/deployments/*", deploys.HandleDelete(s.Repos, s.Builds))
|
||||
|
||||
r.Get("/latest", builds.HandleLast(s.Repos, s.Builds, s.Stages))
|
||||
r.Get("/{number}", builds.HandleFind(s.Repos, s.Builds, s.Stages))
|
||||
r.Get("/{number}/logs/{stage}/{step}", logs.HandleFind(s.Repos, s.Builds, s.Stages, s.Steps, s.Logs))
|
||||
|
|
15
handler/api/repos/builds/deploys/create.go
Normal file
15
handler/api/repos/builds/deploys/create.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package deploys
|
5
handler/api/repos/builds/deploys/create_test.go
Normal file
5
handler/api/repos/builds/deploys/create_test.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Drone Non-Commercial License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package deploys
|
62
handler/api/repos/builds/deploys/delete.go
Normal file
62
handler/api/repos/builds/deploys/delete.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package deploys
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/drone/drone/core"
|
||||
"github.com/drone/drone/handler/api/render"
|
||||
"github.com/drone/drone/logger"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
// HandleDelete returns an http.HandlerFunc that handles an
|
||||
// http.Request to delete a branch entry from the datastore.
|
||||
func HandleDelete(
|
||||
repos core.RepositoryStore,
|
||||
builds core.BuildStore,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
namespace = chi.URLParam(r, "owner")
|
||||
name = chi.URLParam(r, "name")
|
||||
target = chi.URLParam(r, "*")
|
||||
)
|
||||
repo, err := repos.FindName(r.Context(), namespace, name)
|
||||
if err != nil {
|
||||
render.NotFound(w, err)
|
||||
logger.FromRequest(r).
|
||||
WithError(err).
|
||||
WithField("namespace", namespace).
|
||||
WithField("name", name).
|
||||
Debugln("api: cannot find repository")
|
||||
return
|
||||
}
|
||||
|
||||
err = builds.DeleteDeploy(r.Context(), repo.ID, target)
|
||||
if err != nil {
|
||||
render.InternalError(w, err)
|
||||
logger.FromRequest(r).
|
||||
WithError(err).
|
||||
WithField("namespace", namespace).
|
||||
WithField("name", name).
|
||||
Debugln("api: cannot delete deployment")
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}
|
||||
}
|
||||
}
|
5
handler/api/repos/builds/deploys/delete_test.go
Normal file
5
handler/api/repos/builds/deploys/delete_test.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Drone Non-Commercial License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package deploys
|
61
handler/api/repos/builds/deploys/list.go
Normal file
61
handler/api/repos/builds/deploys/list.go
Normal file
|
@ -0,0 +1,61 @@
|
|||
// Copyright 2019 Drone IO, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package deploys
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/drone/drone/core"
|
||||
"github.com/drone/drone/handler/api/render"
|
||||
"github.com/drone/drone/logger"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
)
|
||||
|
||||
// HandleList returns an http.HandlerFunc that writes a json-encoded
|
||||
// list of build history to the response body.
|
||||
func HandleList(
|
||||
repos core.RepositoryStore,
|
||||
builds core.BuildStore,
|
||||
) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
namespace = chi.URLParam(r, "owner")
|
||||
name = chi.URLParam(r, "name")
|
||||
)
|
||||
repo, err := repos.FindName(r.Context(), namespace, name)
|
||||
if err != nil {
|
||||
render.NotFound(w, err)
|
||||
logger.FromRequest(r).
|
||||
WithError(err).
|
||||
WithField("namespace", namespace).
|
||||
WithField("name", name).
|
||||
Debugln("api: cannot find repository")
|
||||
return
|
||||
}
|
||||
|
||||
results, err := builds.LatestDeploys(r.Context(), repo.ID)
|
||||
if err != nil {
|
||||
render.InternalError(w, err)
|
||||
logger.FromRequest(r).
|
||||
WithError(err).
|
||||
WithField("namespace", namespace).
|
||||
WithField("name", name).
|
||||
Debugln("api: cannot list builds")
|
||||
} else {
|
||||
render.JSON(w, results, 200)
|
||||
}
|
||||
}
|
||||
}
|
5
handler/api/repos/builds/deploys/list_test.go
Normal file
5
handler/api/repos/builds/deploys/list_test.go
Normal file
|
@ -0,0 +1,5 @@
|
|||
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
||||
// Use of this source code is governed by the Drone Non-Commercial License
|
||||
// that can be found in the LICENSE file.
|
||||
|
||||
package deploys
|
|
@ -839,6 +839,21 @@ func (mr *MockBuildStoreMockRecorder) LatestBranches(arg0, arg1 interface{}) *go
|
|||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LatestBranches", reflect.TypeOf((*MockBuildStore)(nil).LatestBranches), arg0, arg1)
|
||||
}
|
||||
|
||||
// LatestDeploys mocks base method
|
||||
func (m *MockBuildStore) LatestDeploys(arg0 context.Context, arg1 int64) ([]*core.Build, error) {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "LatestDeploys", arg0, arg1)
|
||||
ret0, _ := ret[0].([]*core.Build)
|
||||
ret1, _ := ret[1].(error)
|
||||
return ret0, ret1
|
||||
}
|
||||
|
||||
// LatestDeploys indicates an expected call of LatestDeploys
|
||||
func (mr *MockBuildStoreMockRecorder) LatestDeploys(arg0, arg1 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "LatestDeploys", reflect.TypeOf((*MockBuildStore)(nil).LatestDeploys), arg0, arg1)
|
||||
}
|
||||
|
||||
// LatestPulls mocks base method
|
||||
func (m *MockBuildStore) LatestPulls(arg0 context.Context, arg1 int64) ([]*core.Build, error) {
|
||||
m.ctrl.T.Helper()
|
||||
|
|
Loading…
Reference in a new issue