piceaTech / node-gitlab-2-github

Migrate Issues, milestones etc from gitlab to github
MIT License
547 stars 134 forks source link

Duplicated attachments in case of throttling #107

Closed ujos closed 2 years ago

ujos commented 2 years ago

In case if GitHub rejects requests (for example because of throttling) the script downloads the same attachment and uploads them to S3 many times (depends on how many times script is executed)

The reason is asynchronous nature of the script. The script downloads GitLab tickets, parses them and downloads attachments ahead. The file name for attachment is generated based on some random number generator (rather than checksum). Thus if I run the script many times, it downloads the same file many times and generates new name for the file.

Following is code in the utils.ts, which causes this behavior:

    const id = crypto.randomBytes(16).toString('hex');
    const newFileName = id + basename;
    const relativePath = githubRepoId ? `${githubRepoId}/${newFileName}` : newFileName;