@@ -43,6 +43,16 @@ type RepositoryLinks struct {
4343 Clone []Link `json:"clone,omitempty"`
4444}
4545
46+ //todo: this could be merged with Ref, PullRequestTarget and PullRequestRef
47+ type Branch struct {
48+ ID string `json:"id"`
49+ DisplayID string `json:"displayId"`
50+ Type string `json:"type"`
51+ LatestCommit string `json:"latestCommit"`
52+ LatestChangeset string `json:"latestChangeset"`
53+ IsDefault bool `json:"isDefault,omitempty"`
54+ }
55+
4656//todo: add the option values as consts
4757type ListRepositoriesOptions struct {
4858 // Name (optional) if specified, this will limit the resulting repository
@@ -186,3 +196,23 @@ func (s *RepositoriesService) ListRecent(ctx context.Context, opts *RecentReposO
186196
187197 return repos , resp , nil
188198}
199+
200+ // GetDefaultBranch returns the default branch of the repository.
201+ //
202+ // Bitbucket Server API doc: https://docs.atlassian.com/bitbucket-server/rest/7.0.1/bitbucket-rest.html#idp204
203+ func (s * RepositoriesService ) GetDefaultBranch (ctx context.Context , projectKey , repositorySlug string ) (* Branch , * Response , error ) {
204+ u := fmt .Sprintf ("projects/%s/repos/%s/branches/default" , projectKey , repositorySlug )
205+
206+ req , err := s .client .NewRequest ("GET" , u , nil )
207+ if err != nil {
208+ return nil , nil , err
209+ }
210+
211+ b := new (Branch )
212+ resp , err := s .client .Do (ctx , req , b )
213+ if err != nil {
214+ return nil , resp , err
215+ }
216+
217+ return b , resp , nil
218+ }
0 commit comments