MunifTanjim / node-bitbucket

Bitbucket API client for Browser and Node.js
https://bitbucketjs.netlify.app
MIT License
106 stars 28 forks source link

Example basic createFileCommit #79

Closed Jamadan closed 3 years ago

Jamadan commented 3 years ago

I've been playing around with this for a while now.

Reading is working fine but I can't figure out what the correct set up is for creating commits.

        const data = new FormData();
    data.append('jamadan.json', {
        me: '123'
    });

    const res = await bitbucket.source.createFileCommit({
        files: 'jamadan.json',
        author: 'Jamadan <dev@jamadan.com>',
        branch: 'testing',
        repo_slug: 'my-repo',
        workspace: 'JamadanTeam',
        message: 'test commit',
        _body: data
    }).then(({ data, headers, status, url }) => {
        console.log({
            data,
            headers,
            status,
            url 
        });
        return {
            data,
            headers,
            status,
            url 
        };
    }).catch(({ message, error, headers, request, status }) => {
        console.log({
            message,
            error,
            headers,
            request,
            status 
        });
    });
{"severity":"WARNING","message":"Request body is missing data."}
>  {"severity":"ERROR","message":"Invalid request, unable to process."}

RESPONSE RECEIVED FROM FUNCTION: 400, {
  "error": {
    "message": "Bad Request",
    "status": "INVALID_ARGUMENT"
  }
}

What's the correct way to use this?

Can someone point me in the direction of an example createFileCommit please?

(reading from repo is working fine, and I have checked all permissions for the user that is used on client creation)

Thanks in advance

MunifTanjim commented 3 years ago

Hey @Jamadan , care to share a snippet of how you solved it? 😃 It might be helpful for someone else facing the same problem.

Jamadan commented 3 years ago

Ha - bit of a 🤦

Issue was elsewhere, however I still haven't figured this out just yet, will report back!

echan00 commented 3 months ago

It would be appreciated if someone can provide an example.. i've followed the documentation and not sure how else to proceed

echan00 commented 3 months ago

here is an example:

      // Create a new commit
      const response = await bitbucketClient.repositories.createSrcFileCommit({
        _body: { 
          "example-file1.json": JSON.stringify(data.json),
          author: 'xxx <admin@xxx.app>',        
          branch: 'dtoday',
          message: 'Update file content',
        },
        repo_slug: repoSlug,
        workspace: workspace,
      });

not possible to guess this via the documentation