Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gustavkj opened this issue Nov 27, 2023 · 5 comments
Open

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

gustavkj opened this issue Nov 27, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@gustavkj
Copy link
Collaborator

gustavkj commented Nov 27, 2023

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 gustavkj added the bug Something isn't working label Nov 27, 2023
@lindell
Copy link
Owner

lindell commented Nov 28, 2023

@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.

@jamestelfer
Copy link
Contributor

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

@gustavkj
Copy link
Collaborator Author

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.

@lindell
Copy link
Owner

lindell commented Nov 28, 2023

@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.

for i := 0; i < 10; i++ {
repo, _, err = retry(ctx, func() (*github.Repository, *github.Response, error) {
return g.ghClient.Repositories.Get(ctx, createdRepo.GetOwner().GetLogin(), createdRepo.GetName())
})
if err != nil {
time.Sleep(time.Second * 3)
continue
}
// The fork does now exist
return g.convertRepo(repo)
}

@gustavkj
Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants