Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
Actualice los archivos de Github a través de la API REST

Estoy trabajando en un creador de sitios web personal. Mi objetivo es poder manipular mi página dentro del navegador y luego presionar el botón 'Publicar' y hacer que el nuevo archivo HTML se confirme en el repositorio de Github donde está alojado mi código.

Pude resolver todo hasta generar el HTML actualizado. Sin embargo, después de revisar la documentación de GitHub, no pude entender realmente cómo se deben procesar los archivos antes o enviarlos al repositorio usando la API. ¿Podría alguien ayudarme?

PD: estaría usando JavaScript para generar el HTML y para las llamadas a la API. Además, si hay un método mejor para lograr mi objetivo, también estoy abierto a ellos.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Usar extremos de contenido del repositorio de GitHub API v3

Es necesario tener en cuenta lo siguiente:

  • El contenido del archivo debe estar en codificación base64.
  • Si el archivo ya existe, debe proporcionar el SHA de blob del archivo, puede obtenerlo a través de Obtener punto final de contenido del repositorio .

Aquí hay un ejemplo de trabajo con Node.js con Octokit API usando el método createOrUpdateFileContents . Lea más sobre esto aquí

Este punto final creará una nueva confirmación con el nuevo contenido del archivo, incluso puede especificar el autor y el autor.

Actualizar el contenido del archivo en GitHub Ver en Fusebit
 // The content of the file should be base64 const content = Buffer.from(`Hello world at ${new Date().toUTCString()}`, 'utf8').toString('base64'); // If the file already exists, you need to provide the sha in order to update the file content. const file_sha = await getFileShaIfExists(octokit, owner, repo, path); const fileContent = await octokit.rest.repos.createOrUpdateFileContents({ owner, repo, path, sha: file_sha, message: 'This is the commit message generated via GitHub API', content, committer: { name: 'demo', email: 'demo@example.com' }, author: { name: 'demo', email: 'demo@example.com' } }); const { commit: { html_url } } = fileContent.data; console.log(`Content updated, see changes at ${html_url}`);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!