← 전체 글

서버리스 함수에서 GitHub API로 커밋 생성하기

Contents API로 충분하다

Git의 blob/tree/commit 오브젝트를 직접 다룰 필요 없이, GitHub REST API의 Contents API(PUT /repos/{owner}/{repo}/contents/{path}) 하나로 파일 생성과 커밋을 동시에 처리할 수 있다. Octokit에서는 createOrUpdateFileContents 메서드다.

await octokit.rest.repos.createOrUpdateFileContents({
  owner,
  repo,
  path: `src/content/posts/${filename}`,
  message: `post: ${title}`,
  content: Buffer.from(markdown).toString('base64'),
  branch,
});

토큰 관리

정리