mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 10:21:00 +00:00
stubs for restarting, canceling builds
This commit is contained in:
parent
fd5a017384
commit
43381827b9
5 changed files with 114 additions and 0 deletions
2
drone.go
2
drone.go
|
@ -79,6 +79,8 @@ func main() {
|
|||
|
||||
repo.GET("/builds", server.GetBuilds)
|
||||
repo.GET("/builds/:number", server.GetBuild)
|
||||
repo.POST("/builds/:number", server.RunBuild)
|
||||
repo.DELETE("/builds/:number", server.KillBuild)
|
||||
repo.GET("/logs/:number/:task", server.GetBuildLogs)
|
||||
repo.POST("/status/:number", server.PostBuildStatus)
|
||||
}
|
||||
|
|
|
@ -95,3 +95,79 @@ func PostBuildStatus(c *gin.Context) {
|
|||
c.JSON(201, in)
|
||||
}
|
||||
}
|
||||
|
||||
// RunBuild accepts a request to restart an existing build.
|
||||
//
|
||||
// POST /api/builds/:owner/:name/builds/:number
|
||||
//
|
||||
func RunBuild(c *gin.Context) {
|
||||
store := ToDatastore(c)
|
||||
repo := ToRepo(c)
|
||||
num, err := strconv.Atoi(c.Params.ByName("number"))
|
||||
if err != nil {
|
||||
c.Fail(400, err)
|
||||
return
|
||||
}
|
||||
build, err := store.Build(repo.FullName, num)
|
||||
if err != nil {
|
||||
c.Fail(404, err)
|
||||
return
|
||||
}
|
||||
|
||||
// must not restart a running build
|
||||
if build.State == common.StatePending || build.State == common.StateRunning {
|
||||
c.Fail(409, err)
|
||||
return
|
||||
}
|
||||
|
||||
build.State = common.StatePending
|
||||
build.Started = 0
|
||||
build.Finished = 0
|
||||
build.Duration = 0
|
||||
build.Statuses = []*common.Status{}
|
||||
for _, task := range build.Tasks {
|
||||
task.State = common.StatePending
|
||||
task.Started = 0
|
||||
task.Finished = 0
|
||||
task.ExitCode = 0
|
||||
}
|
||||
|
||||
err = store.SetBuild(repo.FullName, build)
|
||||
if err != nil {
|
||||
c.Fail(500, err)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO push build to queue
|
||||
|
||||
c.JSON(202, build)
|
||||
}
|
||||
|
||||
// KillBuild accepts a request to kill a running build.
|
||||
//
|
||||
// DELETE /api/builds/:owner/:name/builds/:number
|
||||
//
|
||||
func KillBuild(c *gin.Context) {
|
||||
store := ToDatastore(c)
|
||||
repo := ToRepo(c)
|
||||
num, err := strconv.Atoi(c.Params.ByName("number"))
|
||||
if err != nil {
|
||||
c.Fail(400, err)
|
||||
return
|
||||
}
|
||||
build, err := store.Build(repo.FullName, num)
|
||||
if err != nil {
|
||||
c.Fail(404, err)
|
||||
return
|
||||
}
|
||||
|
||||
// must not restart a running build
|
||||
if build.State != common.StatePending && build.State != common.StateRunning {
|
||||
c.Fail(409, err)
|
||||
return
|
||||
}
|
||||
|
||||
// TODO tell queue to cancel build
|
||||
|
||||
c.Writer.WriteHeader(202)
|
||||
}
|
||||
|
|
|
@ -87,6 +87,17 @@
|
|||
$scope.error = err;
|
||||
});
|
||||
|
||||
$scope.restart = function() {
|
||||
builds.restart(fullName, number).catch(function(err){
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.cancel = function() {
|
||||
builds.cancel(fullName, number).catch(function(err) {
|
||||
$scope.error = err;
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
angular
|
||||
|
|
|
@ -26,6 +26,26 @@
|
|||
this.get = function(repoName, buildNumber) {
|
||||
return $http.get('/api/repos/'+repoName+'/builds/'+buildNumber);
|
||||
};
|
||||
|
||||
/**
|
||||
* Restarts a build.
|
||||
*
|
||||
* @param {string} Name of the repository.
|
||||
* @param {number} Number of the build.
|
||||
*/
|
||||
this.restart = function(repoName, buildNumber) {
|
||||
return $http.post('/api/repos/' + repoName+'/builds/'+buildNumber);
|
||||
};
|
||||
|
||||
/**
|
||||
* Cancels a running build.
|
||||
*
|
||||
* @param {string} Name of the repository.
|
||||
* @param {number} Number of the build.
|
||||
*/
|
||||
this.cancel = function(repoName, buildNumber) {
|
||||
return $http.delete('/api/repos/'+repoName+'/builds/'+buildNumber);
|
||||
};
|
||||
}
|
||||
|
||||
angular
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
<a href="/{{ repo.full_name }}">Back</a>
|
||||
|
||||
<div>
|
||||
<button ng-if="build.state !== 'pending' && build.state !== 'started'" ng-click="restart()">Restart</button>
|
||||
<button ng-if="build.state === 'pending' || build.state === 'started'" ng-click="cancel()">Cancel</button>
|
||||
</div>
|
||||
|
||||
<dl>
|
||||
<dt>Build State</dt>
|
||||
<dd>{{ build.state }}</dd>
|
||||
|
|
Loading…
Reference in a new issue