multi-gitter icon indicating copy to clipboard operation
multi-gitter copied to clipboard

Using code search together with fork mode does not seem to work

Open gustavkj opened this issue 2 years ago • 5 comments

Describe the bug When using multi-gitter with code-search set to find repos and fork: true, I found that the run failed with the following error for most repos:

could not verify if branch already exists: repository not found

But running the same config apart from replacing code-search with a list of repos (same as were found by the code search), worked as expected.

Config file
# Base URL of the (v3) GitHub API, needs to be changed if GitHub enterprise is used. Or the url to a self-hosted GitLab instance.
base-url: https://github.company.com/api/v3

# The name of the branch where changes are committed.
branch: update-internal-actions

# Use a code search to find a set of repositories to target (GitHub only). Repeated results from a given repository will be ignored, forks are NOT included by default (use `fork:true` to include them). See the GitHub documentation for full syntax: https://docs.github.com/en/search-github/searching-on-github/searching-code.
code-search: "internal/github-action extension:yml extension:yaml path:.github -org:org-a -org:org-b -org:ab-archive"

# The commit message. Will default to title + body if none is set.
commit-message: "refactor: update internal actions"

# What should happen if the branch already exist.
# Available values:
#   skip: Skip making any changes to the existing branch and do not create a new pull request.
#   replace: Replace the existing content of the branch by force pushing any new changes, then reuse any existing pull request, or create a new one if none exist.
conflict-strategy: skip

# Create pull request(s) as draft.
draft: false

# Run without pushing changes or creating pull requests
dry-run: false

# Fork the repository instead of creating a new branch on the same owner.
fork: true

# The type of git implementation to use.
# Available values:
#   go: Uses go-git, a Go native implementation of git. This is compiled with the multi-gitter binary, and no extra dependencies are needed.
#   cmd: Calls out to the git command. This requires git to be installed and available with by calling "git".
git-type: go

# The file where all logs should be printed to. "-" means stdout
log-file: "-"

# The formatting of the logs. Available values: text, json, json-pretty
log-format: text

# The level of logging that should be made. Available values: trace, debug, info, error
log-level: info

# The file that the output of the script should be outputted to. "-" means stdout
output: "-"

# The body of the commit message. Will default to everything but the first line of the commit message if none is set.
pr-body: |
  This is an automated PR to update the internal actions in this repository.

To Reproduce Steps to reproduce the behavior:

  1. I want to update workflow files across multiple organizations (in which I'm not a member) using forks
  2. Run multi-gitter run ./replace.sh --config ./multi-gitter-config.yml --token $GITHUB_TOKEN
  3. For most repos the following logs where printed:
    INFO[0007] Cloning and running script                    repo=org-a/repo-a
    INFO[0008] Forking repository                            repo=org-a/repo-a
    INFO[0009] could not verify if branch already exists: repository not found  repo=org-a/repo-a
    

Expected behavior Expected code to be pushed to forks and pull requests to be created towards the upstream repos.

Additional context Add any other context about the problem here. It is for example often useful to include detailed logs from a run with --log-level=trace.

gustavkj avatar Nov 27 '23 09:11 gustavkj

@jamestelfer Do you know what might be going on here? It seems that it should return the same types of repo here and thus not be any difference. Will be able to look into this in a few days.

lindell avatar Nov 28 '23 06:11 lindell

I'm not sure, I'll see if I can reproduce it

jamestelfer avatar Nov 28 '23 06:11 jamestelfer

Another difference, I realize, is that the forks already existed during the second (non-code-search) run. So, that's also something to take into consideration.

gustavkj avatar Nov 28 '23 07:11 gustavkj

@gustavkj Could you rerun with codesearch again? I think it's more likely that the waiting for the fork to become available is to early. This worked before, but it could be that GitHub is no longer ready to fetch the data the same second as the repo becomes available.

https://github.com/lindell/multi-gitter/blob/c7a6e69aafb87efafa25248c73d7afa1a8ee76ac/internal/scm/github/github.go#L773-L783

lindell avatar Nov 28 '23 07:11 lindell

Could you rerun with codesearch again?

I re-ran it later yesterday, but only for one repo (still using code search) with a config something like this: code-search: "internal/github-action extension:yml extension:yaml path:.github repo:org-c/repo-name" and then it worked. I had previously deleted the fork for that repo.

Also, on the initial run (where most 30 out of 33 repos failed with the error described in this issue) one PR was created as expected and I had not forked that repo previously.

gustavkj avatar Nov 28 '23 08:11 gustavkj