MCPcopy Index your code
hub / github.com/1Password/for-open-source / commitFile

Method commitFile

script/github.go:164–220  ·  view source on GitHub ↗
(filePath string, content []byte, message string, update bool)

Source from the content-addressed store, hash-verified

162}
163
164func (g *GitHub) commitFile(filePath string, content []byte, message string, update bool) error {
165 commitBranch := "main"
166
167 if isTesting() {
168 debugMessage(
169 fmt.Sprintf(
170 "Commiting the following contents to a file located at \"%s\" with the commit message \"%s\":",
171 filePath, message,
172 ),
173 string(content),
174 )
175
176 return nil
177 }
178
179 opts := &github.RepositoryContentFileOptions{
180 Content: content,
181 Message: &message,
182 Branch: &commitBranch,
183 }
184
185 var err error
186 if update {
187 fileContent, _, _, err := g.Client.Repositories.GetContents(
188 context.Background(),
189 g.RepoOwner,
190 g.RepoName,
191 filePath,
192 &github.RepositoryContentGetOptions{Ref: commitBranch},
193 )
194
195 if err != nil {
196 return err
197 }
198
199 sha := fileContent.GetSHA()
200 opts.SHA = &sha
201
202 _, _, err = g.Client.Repositories.UpdateFile(
203 context.Background(),
204 g.RepoOwner,
205 g.RepoName,
206 filePath,
207 opts,
208 )
209 } else {
210 _, _, err = g.Client.Repositories.CreateFile(
211 context.Background(),
212 g.RepoOwner,
213 g.RepoName,
214 filePath,
215 opts,
216 )
217 }
218
219 return err
220}
221

Callers 2

CommitNewFileMethod · 0.95
UpdateFileMethod · 0.95

Calls 3

isTestingFunction · 0.85
debugMessageFunction · 0.85
UpdateFileMethod · 0.80

Tested by

no test coverage detected