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

access to a repositories dependency graph #54

Open
ghost opened this issue Dec 22, 2019 · 4 comments
Open

access to a repositories dependency graph #54

ghost opened this issue Dec 22, 2019 · 4 comments
Labels

Comments

@ghost
Copy link

ghost commented Dec 22, 2019

Hi,

Hope you are all well !

I wonder if you could provide me the example for accessing the DependencyGraphManifest for a repository.

Ref. https://developer.github.com/v4/previews/#access-to-a-repositories-dependency-graph

I cannot understand how to build the query.

Thanks in advance for your help.

Cheers,
X

@dmitshur
Copy link
Member

Hello.

DependencyGraphManifest is a part of API preview, meaning it's not included by default. To use it, the Accept header must have application/vnd.github.hawkgirl-preview+json set. This is described at https://developer.github.com/v4/previews/#access-to-a-repositories-dependency-graph.

There's an open issue about finding a way for this library to support previews, see #34. It is not complete. Until more progress is made, the best way I can recommend (and what others have done, e.g., see #45) is to make a fork and modify it to add preview API support that you're looking for.

Alternatively, you can wait until GitHub graduates said preview API into their normal API.

Hope that helps.

@ghost
Copy link
Author

ghost commented Dec 24, 2019

@djoksimo any plans to fix it ? or it would be awesome if you solve this incomplete pull request.

@djoksimo
Copy link

djoksimo commented Dec 24, 2019

@x0rzkov I will most likely not be able to complete the pull request soon but there are a few alternatives that may help.

You could use http.RoundTripper to attach HTTP headers directly in your code before calling any queries. Check out this stackoverflow link.

Optional:

My fork of this package (https://github.com/djoksimo/githubv4) autogenerates the preview mode Go GraphQL schema by fetching the preview headers directly from GitHub. See how the headers are attached and check out the diff here

Feel free to use my fork as inspiration, or to fork my fork. My fork may be a bit outdated so I cannot guarantee total functionality. Let me know if you have any questions! 😄

@nehzata
Copy link

nehzata commented Sep 27, 2023

If anyone else needs to do this:

type Transport struct {
	T http.RoundTripper
}

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
	req.Header.Add("Accept", "application/vnd.github.hawkgirl-preview+json")
	return t.T.RoundTrip(req)
}

func NewTransport(T http.RoundTripper) *Transport {
	if T == nil {
		T = http.DefaultTransport
	}
	return &Transport{T}
}

var q struct {}
var vars map[string]any = map[string]any{}

httpClient := &http.Client{Transport: httpgh.NewTransport(nil)}

ctx := context.WithValue(
	context.Background(), 
	oauth2.HTTPClient, 
	&http.Client{Transport: httpgh.NewTransport(nil)},
)
client := githubv4.NewClient(
	oauth2.NewClient(
		ctx,
		oauth2.StaticTokenSource(&oauth2.Token{
			AccessToken: ghAccesstoken,
		}),
	),
)

err = client.Query(ctx, &q, vars)
if err != nil {
	logger.WithError(err).Error("failed to query repos")
	return false, err
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants