github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/git/git_plugin.go (about)

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