Skip to content

[BUG]: Unable to create file directly while using createOrUpdateTextFile #300

@venkatesh-kl

Description

@venkatesh-kl

What happened?

I have tried to update a file in a git repository using the below script. I have noticed that using this as a plugin works as expected. However, when trying to use it as a standalone method. I don't see any action happen. The log I see is { "response": {} } when I use the standalone block of code. I prefer to keep things simple, so I prefer the standalone apporach. Please suggest me on what's wrong or let me know if I can help if it's a bug.

import { Octokit } from "@octokit/core";
import { createOrUpdateTextFile } from "@octokit/plugin-create-or-update-text-file";
import dotenv from "dotenv";
dotenv.config();

const OWNER = "user";
const REPO = "repository-name";
const BRANCH = "main";

const COMMITTER = {
  name: "committer",
  email: "[email protected]",
};

const path = "test-file.json";
const opts = {
  owner: OWNER,
  repo: REPO,
  path,
  committer: COMMITTER,
  branch: BRANCH,
  message: `updated file:"${path}"`,
  content: JSON.stringify({ message: "hello world! how are you" }),
};

// Plugin Code - works
const MyOctokit = Octokit.plugin(createOrUpdateTextFile);
const myOctokit = new MyOctokit({ auth: process.env.GH_TOKEN });
const pluginResponse = await myOctokit.createOrUpdateTextFile(opts);
console.log(`------------ plugin response --------------`);
console.log(JSON.stringify({ response: pluginResponse }));
console.log(`--------------------------`);

// standalone - doesn't work
const octokit = new Octokit({ auth: process.env.GH_TOKEN });
const response = await createOrUpdateTextFile(myOctokit, opts);
console.log(`------------ std response --------------`);
console.log(JSON.stringify({ response: response }));
console.log(`--------------------------`);

Versions

@octokit/core: "6.1.2"
@octokit/plugin-create-or-update-text-file: "5.1.0"
Node: "18.19.0"

Relevant log output

There's some additional

------------ plugin response --------------
{"response":{"url":"https://api.github.com/repos/user/repository-name/contents/test-file.json","status":200,"headers":{"access-control-allow-origin":"*","access-control-expose-headers":"ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset","cache-control":"private, max-age=60, s-maxage=60","content-encoding":"gzip","content-security-policy":"default-src 'none'","content-type":"application/json; charset=utf-8","date":"Tue, 29 Oct 2024 05:51:09 GMT","etag":"W/\"7728a1b6698048bb3106b285280957087375f28f7667d94a90687b27a04c7293\"","github-authentication-token-expiration":"2024-11-27 09:13:36 UTC","referrer-policy":"origin-when-cross-origin, strict-origin-when-cross-origin","server":"github.com","strict-transport-security":"max-age=31536000; includeSubdomains; preload","transfer-encoding":"chunked","vary":"Accept, Authorization, Cookie, X-GitHub-OTP,Accept-Encoding, Accept, X-Requested-With","x-accepted-oauth-scopes":"","x-content-type-options":"nosniff","x-frame-options":"deny","x-github-api-version-selected":"2022-11-28","x-github-media-type":"github.v3; format=json","x-github-request-id":"6FA0:233A44:1FEA3A2:2253434:672077CC","x-oauth-scopes":"repo","x-ratelimit-limit":"5000","x-ratelimit-remaining":"4982","x-ratelimit-reset":"1730184025","x-ratelimit-resource":"core","x-ratelimit-used":"18","x-xss-protection":"0"},"data":{"content":{"name":"test-file.json","path":"test-file.json","sha":"ef39d432095d2f4a03c2ddc97fbbe3fc3dc501bb","size":38,"url":"https://api.github.com/repos/user/repository-name/contents/test-file.json?ref=main","html_url":"https://github.com/user/repository-name/blob/main/test-file.json","git_url":"https://api.github.com/repos/user/repository-name/git/blobs/ef39d432095d2f4a03c2ddc97fbbe3fc3dc501bb","download_url":"https://raw.githubusercontent.com/user/repository-name/main/test-file.json?token=AX4QTAG6ZVK5SKXYJJAM4VDHEB4AS","type":"file","_links":{"self":"https://api.github.com/repos/user/repository-name/contents/test-file.json?ref=main","git":"https://api.github.com/repos/user/repository-name/git/blobs/ef39d432095d2f4a03c2ddc97fbbe3fc3dc501bb","html":"https://github.com/user/repository-name/blob/main/test-file.json"}},"commit":{"sha":"831a6a18fbbd3db5360252f9aa0df1c93652c8f3","node_id":"C_kwDONGzYQNoAKDgzMWE2YTE4ZmJiZDNkYjUzNjAyNTJmOWFhMGRmMWM5MzY1MmM4ZjM","url":"https://api.github.com/repos/user/repository-name/git/commits/831a6a18fbbd3db5360252f9aa0df1c93652c8f3","html_url":"https://github.com/user/repository-name/commit/831a6a18fbbd3db5360252f9aa0df1c93652c8f3","author":{"name":"Venkatesh KL","email":"[email protected]","date":"2024-10-29T05:51:09Z"},"committer":{"name":"Venkatesh KL","email":"[email protected]","date":"2024-10-29T05:51:09Z"},"tree":{"sha":"4866b38e56912aba49426d0bb9b1b5534a5218eb","url":"https://api.github.com/repos/user/repository-name/git/trees/4866b38e56912aba49426d0bb9b1b5534a5218eb"},"message":"updated file:\"test-file.json\"","parents":[{"sha":"91c95ee5d98641d9334e8a1aada7887e9a2bd259","url":"https://api.github.com/repos/user/repository-name/git/commits/91c95ee5d98641d9334e8a1aada7887e9a2bd259","html_url":"https://github.com/user/repository-name/commit/91c95ee5d98641d9334e8a1aada7887e9a2bd259"}],"verification":{"verified":false,"reason":"unsigned","signature":null,"payload":null}}},"updated":true,"deleted":false,"content":"{\"message\":\"hello world! how are you\"}"}}
--------------------------
------------ std response --------------
{"response":{}}
--------------------------


### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is being looked at and prioritizedType: BugSomething isn't working as documentedreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions