Skip to content

Commit

Permalink
Merge pull request #328 from drone/PIPE-23808
Browse files Browse the repository at this point in the history
feat: [PIPE-23808]: integrate author details with the harness commits API
  • Loading branch information
karansaraswat19 authored Dec 3, 2024
2 parents d5ed63c + 31d79c4 commit d9147fb
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 99 deletions.
4 changes: 2 additions & 2 deletions scm/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ type (
// Find returns the repository file content by path.
Find(ctx context.Context, repo, path, ref string) (*Content, *Response, error)

// Create creates a new repositroy file.
// Create creates a new repository file.
Create(ctx context.Context, repo, path string, params *ContentParams) (*Response, error)

// Update updates a repository file.
Update(ctx context.Context, repo, path string, params *ContentParams) (*Response, error)

// Delete deletes a reository file.
// Delete deletes a repository file.
Delete(ctx context.Context, repo, path string, params *ContentParams) (*Response, error)

// List returns a list of contents in a repository directory by path. It is
Expand Down
196 changes: 99 additions & 97 deletions scm/driver/harness/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (s *contentService) Create(ctx context.Context, repo, path string, params *
Title: params.Message,
Actions: []action{a},
BypassRules: true,
Author: identity{
Name: params.Signature.Name,
Email: params.Signature.Email,
},
}

res, err := s.client.do(ctx, "POST", endpoint, in, nil)
Expand All @@ -81,6 +85,10 @@ func (s *contentService) Update(ctx context.Context, repo, path string, params *
Title: params.Message,
Actions: []action{a},
BypassRules: true,
Author: identity{
Name: params.Signature.Name,
Email: params.Signature.Email,
},
}

res, err := s.client.do(ctx, "POST", endpoint, in, nil)
Expand All @@ -105,6 +113,10 @@ func (s *contentService) Delete(ctx context.Context, repo, path string, params *
Title: params.Message,
Actions: []action{a},
BypassRules: true,
Author: identity{
Name: params.Signature.Name,
Email: params.Signature.Email,
},
}

res, err := s.client.do(ctx, "POST", endpoint, in, nil)
Expand All @@ -123,109 +135,99 @@ func (s *contentService) List(ctx context.Context, repo, path, ref string, _ scm
return convertContentInfoList(out.Content.Entries), res, err
}

type editFile struct {
Actions []action `json:"actions"`
Branch string `json:"branch"`
Message string `json:"message"`
NewBranch string `json:"new_branch"`
Title string `json:"title"`
type (
identity struct {
Name string `json:"name"`
Email string `json:"email"`
}

BypassRules bool `json:"bypass_rules"`
}
editFile struct {
Actions []action `json:"actions"`
Author identity `json:"author"`
Branch string `json:"branch"`
Message string `json:"message"`
NewBranch string `json:"new_branch"`
Title string `json:"title"`

type action struct {
Action string `json:"action"`
Encoding string `json:"encoding"`
Path string `json:"path"`
Payload string `json:"payload"`
Sha string `json:"sha"`
}
BypassRules bool `json:"bypass_rules"`
}

type fileContent struct {
Type string `json:"type"`
Sha string `json:"sha"`
Name string `json:"name"`
Path string `json:"path"`
LatestCommit struct {
Sha string `json:"sha"`
Title string `json:"title"`
Message string `json:"message"`
Author struct {
Identity struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"author"`
Committer struct {
Identity struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"committer"`
} `json:"latest_commit"`
Content struct {
action struct {
Action string `json:"action"`
Encoding string `json:"encoding"`
Data string `json:"data"`
Size int `json:"size"`
} `json:"content"`
}
Path string `json:"path"`
Payload string `json:"payload"`
Sha string `json:"sha"`
}

type contentList struct {
Type string `json:"type"`
Sha string `json:"sha"`
Name string `json:"name"`
Path string `json:"path"`
LatestCommit struct {
Sha string `json:"sha"`
Title string `json:"title"`
Message string `json:"message"`
Author struct {
Identity struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"author"`
Committer struct {
Identity struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"committer"`
} `json:"latest_commit"`
Content struct {
Entries []fileEntry `json:"entries"`
} `json:"content"`
}
fileContent struct {
Type string `json:"type"`
Sha string `json:"sha"`
Name string `json:"name"`
Path string `json:"path"`
LatestCommit struct {
Sha string `json:"sha"`
Title string `json:"title"`
Message string `json:"message"`
Author struct {
Identity identity `json:"identity"`
When time.Time `json:"when"`
} `json:"author"`
Committer struct {
Identity identity `json:"identity"`
When time.Time `json:"when"`
} `json:"committer"`
} `json:"latest_commit"`
Content struct {
Encoding string `json:"encoding"`
Data string `json:"data"`
Size int `json:"size"`
} `json:"content"`
}

type fileEntry struct {
Type string `json:"type"`
Sha string `json:"sha"`
Name string `json:"name"`
Path string `json:"path"`
LatestCommit struct {
Sha string `json:"sha"`
Title string `json:"title"`
Message string `json:"message"`
Author struct {
Identity struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"author"`
Committer struct {
Identity struct {
Name string `json:"name"`
Email string `json:"email"`
} `json:"identity"`
When time.Time `json:"when"`
} `json:"committer"`
} `json:"latest_commit"`
}
contentList struct {
Type string `json:"type"`
Sha string `json:"sha"`
Name string `json:"name"`
Path string `json:"path"`
LatestCommit struct {
Sha string `json:"sha"`
Title string `json:"title"`
Message string `json:"message"`
Author struct {
Identity identity `json:"identity"`
When time.Time `json:"when"`
} `json:"author"`
Committer struct {
Identity identity `json:"identity"`
When time.Time `json:"when"`
} `json:"committer"`
} `json:"latest_commit"`
Content struct {
Entries []fileEntry `json:"entries"`
} `json:"content"`
}

fileEntry struct {
Type string `json:"type"`
Sha string `json:"sha"`
Name string `json:"name"`
Path string `json:"path"`
LatestCommit struct {
Sha string `json:"sha"`
Title string `json:"title"`
Message string `json:"message"`
Author struct {
Identity identity `json:"identity"`
When time.Time `json:"when"`
} `json:"author"`
Committer struct {
Identity identity `json:"identity"`
When time.Time `json:"when"`
} `json:"committer"`
} `json:"latest_commit"`
}
)

func convertContentInfoList(from []fileEntry) []*scm.ContentInfo {
to := []*scm.ContentInfo{}
Expand Down

0 comments on commit d9147fb

Please sign in to comment.