-
Notifications
You must be signed in to change notification settings - Fork 8
/
repository.go
103 lines (79 loc) · 3.04 KB
/
repository.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package repositories
import (
"io"
"github.com/reviewboard/rb-gateway/repositories/events"
)
// RepositoryInfo is a generic representation of a repository, containing
// a name and a path to the repository.
type RepositoryInfo struct {
Name string
Path string
}
// Repository is an interface that contains functions to perform actions on
// repositories, such as getting the file contents or checking if a file
// exists.
type Repository interface {
// GetName returns the name of the repository.
GetName() string
// GetPath returns the path of the repository.
GetPath() string
// Return the name of the SCM.
GetScm() string
// GetFile takes a file ID and returns the file contents as a byte array.
// If an error occurs, it will also be returned.
GetFile(id string) ([]byte, error)
// GetFileByCommit takes a commit and a file path pair, and returns the
// file contents as a byte array. If an error occurs, it will also be
// returned.
GetFileByCommit(commit, filepath string) ([]byte, error)
// FileExists takes a file ID and returns true if the file is found in the
// repository; false otherwise. If an error occurs, it will also be
// returned.
FileExists(id string) (bool, error)
// FileExistsByCommit takes a commit and file path pair, and returns true
// if the file is found in the repository; false otherwise. If an error
// occurs, it will also be returned.
FileExistsByCommit(commit, filepath string) (bool, error)
// GetBranches returns all the branches in the repository as a JSON byte
// array. If an error occurs, it will also be returned.
GetBranches() ([]Branch, error)
// GetCommit returns all the commits in the repository starting at the
// specified branch as a JSON byte array. It also takes an optional start
// commit id, which will return all commits starting from the start commit
// id instead. If an error occurs, it will also be returned.
GetCommits(branch string, start string) ([]CommitInfo, error)
// GetCommit returns the commit in the repository provided by the commit
// id as a JSON byte array. If an error occurs, it will also be returned.
GetCommit(commitId string) (*Commit, error)
// Parse the raw payload from the given event.
ParseEventPayload(event string, input io.Reader) (events.Payload, error)
// Install scripts to trigger webhooks.
InstallHooks(cfgPath string, force bool) error
}
// Metadata about a commit.
type CommitInfo struct {
// The author of the commit.
Author string `json:"author"`
// The unique identifier of the commit.
Id string `json:"id"`
// The date the commit was authored.
Date string `json:"date"`
// The commit's message.
Message string `json:"message"`
// The unique identifier of the parent commit.
ParentId string `json:"parent_id"`
}
// A commit with metadata and a diff.
type Commit struct {
// Commit metadata.
CommitInfo
// The contents of the diff.
Diff string `json:"diff"`
}
// Information about a branch in an SCM.
type Branch struct {
// The name of the branch.
Name string `json:"name"`
// The commit ID the branch points to.
Id string `json:"id"`
}