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

json: cannot unmarshal array into Go value of type github.Repository #96

Closed
matross-gh opened this issue Jan 26, 2024 · 5 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@matross-gh
Copy link

Quick Note - This whole thing could simply be that at one time I thought that actions-sync created the organization if it did not exist, then created the repository, again if it did not exist, then finally push the repo. Just to REALLY sort things out, I event did the command: gh-org-admin-promote -u ghe-admin -o actions.

Error

json: cannot unmarshal array into Go value of type github.Repository

Command

actions-sync sync --cache-dir 'c:\temp' --destination-token 'abc123' --destination-url 'http://<serverFQDN>' --repo-name docker/bake-action

Environment

Windows 11 23H2 (OS Build 22631.3007)
PowerShell 7.4.1
Go v1.21.6
Chocolatey v2.2.2

Note: I am using this to test the process. I have a classic token which as the following rights: admin:enterprise, admin:org, repo, site_admin, workflow

Narrative

I have the latest version of actions-sync saved in my c:\program files\dotnet directory. This directory is in the path. I am using PowerShell 7.4.1 to execute the command as noted above. I am attempting to sync from my Windows workstation to a GitHub Version 3.10.5 instance.

Expectations

sync the repository of my choice from https://github.com to my instance using actions-sync and the sync command. If organization does not exist, the tool creates the organization then creates the repository and pushes the fetched repository to the newly created organization and repository. Could be me, but I thought earlier versions did this?

Steps and Outcomes

Note: I am using this to test the process. I have a classic token which as the following rights: admin:enterprise, admin:org, repo, site_admin, workflow

  1. Issue Action Sync Command
    • command: actions-sync sync --cache-dir 'c:\temp' --destination-token 'abc123' --destination-url 'http://myserver' --repo-name docker/bake-action
    • result: error creating github repository docker/bake-action: error creating organization docker: GET https://myserver/api/v3/admin/organizations: 404 Not Found []

At this point, I go and create the docker organization in my instance and re-issue the command

  1. Issue Action Sync Command
    • command: actions-sync sync --cache-dir 'c:\temp' --destination-token 'abc123' --destination-url 'http://myserver' --repo-name docker/bake-action
    • result: error creating github repository docker/bake-action: error creating repository docker/bake-action: json: cannot unmarshal array into Go value of type github.Repository

At this point I create the bake-action repository in the docker organization and re-issue the command

  1. Issue Action Sync Command
    • command: actions-sync sync --cache-dir 'c:\temp' --destination-token 'abc123' --destination-url 'http://myserver' --repo-name docker/bake-action
    • result:
      fetching * refs for docker/bake-action ...
      not using impersonation for the requests
      syncing docker/bake-action
      Existing repo docker/bake-action
      successfully synced docker/bake-action
@shawnHartsell
Copy link
Contributor

Hi @matross-gh thanks for filing an issue! If you could could you let us know what version of actions-sync you encountered this issue in? I noticed that this project is not using matrix build for Windows so it very well could be a Go related issue. We'll work on reproducing the issue internally as well.

@shawnHartsell shawnHartsell added the bug Something isn't working label Apr 8, 2024
@matross-gh
Copy link
Author

@shawnHartsell Hi there! Sure thing! I am using GHES Actions Sync v0.2 obtained from issuing the command actions-sync version.

@shawnHartsell
Copy link
Contributor

shawnHartsell commented Apr 17, 2024

@matross-gh I was able to repro this, and admit should have seen the problem sooner 😢. I believe you're encountering this issue b/c your using http instead of https for --destination-url. Can you update your command and see if that works for you?

Details

When http is used, the REST API returns a 301. Furthermore, the http.Client that's used to create the go-github Client
is configured with the default behavior to follow redirects, which results in a GET being executed to the endpoint instead.

In the case of creating a repo (the last action in the sync command) what actually ends up happening is that repos for the user/org are being fetched. The response body for fetching repos is an array which causes the Marshaling error ([]Repo to Repo)

Below is an example taken from one of my test GHES instance via curl:

curl -v -L \
  -X GET \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer REDACTED" \
  -H "X-GitHub-Api-Version: 2022-11-28" \
  http://REDACTED/api/v3/orgs/shawnhartsell/repos \
  -d '{"name":"Hello-World","description":"This is your first repository","homepage":"https://github.com","private":false,"has_issues":true,"has_projects":true,"has_wiki":true}'
...
< HTTP/1.1 301 Moved Permanently
< Content-Length: 0
* Please rewind output before next send
< Location: https://REDACTED/api/v3/orgs/shawnhartsell/repos
< connection: close
<
* Closing connection
* Clear auth, redirects to port from 80 to 443
* Issue another request to this URL: 'https://REDACTED/api/v3/orgs/shawnhartsell/repos'
* Switch from POST to GET
* ....TLS STUFF REMOVED FOR BREVITY
> GET /api/v3/orgs/shawnhartsell/repos HTTP/2
> Host: REDACTED
> User-Agent: curl/8.4.0
> Accept: application/vnd.github+json
> X-GitHub-Api-Version: 2022-11-28
>
< HTTP/2 401
< server: GitHub.com
< date: Wed, 17 Apr 2024 16:47:20 GMT
< content-type: application/json; charset=utf-8
< content-length: 135
< x-github-enterprise-version: 3.10.9
{
  "message": "Must authenticate to access this API.",
  "documentation_url": "https://docs.github.com/enterprise-server@3.10/rest"
}

@shawnHartsell shawnHartsell self-assigned this Apr 17, 2024
@matross-gh
Copy link
Author

@shawnHartsell Wow! Thank you! That worked! I can't believe I did that! sheesh! Using same version with same tooling on my laptop, no change there.

Command (with HTTPS on --destination-url parameter)
actions-sync sync --cache-dir 'c:\temp' --destination-token 'ghp_abc123' --destination-url 'https://myinstanceFQDN' --repo-name 'docker/bake-action'

Output
image

Pardon the use of ghe-admin, just forming the repeatable process here. I will be using a different account for this action.

Thank you very much and my apologies for such a late reply!

@shawnHartsell
Copy link
Contributor

No problem! Glad that resolved your issue. As a follow up I created #128 to force the use of HTTPs. I also noticed that the version command is not outputting correct data so I created #129 as well.

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

2 participants