forked from evergreen-ci/evergreen
/
git_plugin.go
54 lines (44 loc) · 1.24 KB
/
git_plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package git
import (
"net/http"
"github.com/evergreen-ci/evergreen/plugin"
"github.com/gorilla/mux"
)
func init() {
plugin.Publish(&GitPlugin{})
}
const (
GetProjectCmdName = "get_project"
ApplyPatchCmdName = "apply_patch"
GitPluginName = "git"
GitPatchPath = "patch"
GitPatchFilePath = "patchfile"
)
// GitPlugin handles fetching source code and applying patches
// using the git version control system.
type GitPlugin struct{}
// Name implements Plugin Interface.
func (self *GitPlugin) Name() string {
return GitPluginName
}
func (self *GitPlugin) GetAPIHandler() http.Handler {
r := mux.NewRouter()
r.Path("/" + GitPatchFilePath + "/{patchfile_id}").Methods("GET").HandlerFunc(servePatchFile)
r.HandleFunc("/"+GitPatchPath, servePatch) // GET
r.HandleFunc("/", http.NotFound)
return r
}
func (self *GitPlugin) Configure(map[string]interface{}) error {
return nil
}
// NewCommand returns requested commands by name. Fulfills the Plugin interface.
func (self *GitPlugin) NewCommand(cmdName string) (plugin.Command, error) {
switch cmdName {
case GetProjectCmdName:
return &GitGetProjectCommand{}, nil
case ApplyPatchCmdName:
return &GitApplyPatchCommand{}, nil
default:
return nil, &plugin.ErrUnknownCommand{cmdName}
}
}