Octokit: Cannot create multible Labels

245 Views Asked by At

Cannot create multible Labels

Code Sample:

Promise.all(
    srcRepoReq.data.map(async (label) => {
        const newLabel: ghLabel = {
            name: label.name,
            color: label.color,
            description: label.description,
        };
        const createLabelReq = await octokit.request('POST /repos/{username}/{trgtRepo}/labels', {
            username: cfg.username,
            trgtRepo: cfg.trgtRepo,
            name: newLabel.name,
            color: newLabel.color,
            description: newLabel.description,
        });
        Terminal.writeInfo(createLabelReq.status);
        Terminal.writeInfo(newLabel.name);
    })
);

What i want to do:

I want to create multible Labels using GitHub's @octokit/core API Client.

Problem:

All those promises don't seem to be executed. I won't get any Text from those two Terminal.* Methods. Also no Label is showing up at the Repo. But if i execute the Code outside of Promise.all(srcRepoReq.data.map(...)); it works perfectly fine and the Labels are getting created. But i have to exec every Request manually and hardcode them into the code. Which is not what i want to do. I want to create Labels based on an Array of Elements. Type:

type ghLabel  = {
    name: string;
    color: string;
    description: string;
};

This contains all Data that is required by the GitHub API to create a label.

Could this be 'cause of some restriction on the GitHub-Side ? Only <number> of requests per <time> ?

To Clarify

yes. the types are correct. I already verified that.

Any Solutions ?

1

There are 1 best solutions below

2
On

As you mention, an abuse rate limit could the root cause of the issue you are having. Did you try to catch why the Promise.all is failing to get more info? How many reposito (more or less) are we talking about?

I would suggest to try using Throttling Octokit's plugin (@octokit/plugin-throttling) if you find out you are hitting API's limit.

Also, as an extra point, I invite you to take a look into Octoherd (from the creator of Octokit). It gives you a create-script-utility to do massive tasks to repositories as you want to do here with labels.

If you have problems running Octoherd or Octokit Plugin open an issue in those repos, the creator and other contributors are quite active there.