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

Setting headers for all requests #951

Closed
faustbrian opened this issue Jun 22, 2019 · 4 comments

Comments

@faustbrian
Copy link

commented Jun 22, 2019

I am currently building a bot that relies on some features that are locked behind previews of the GitHub API. Since I am required to send the preview I want to use via an Accept Header I am currently doing it like in the snippet below.

export const listIssues = async (context: Context, { owner, repo, since }) =>
	context.github.paginate(
		context.github.issues.listForRepo.endpoint.merge({
			owner,
			repo,
			state: "all",
			since,
			per_page: 100,
			headers: {
				accept: "application/vnd.github.squirrel-girl-preview",
			},
		}),
	);

Is there a way to set those headers globally for all requests I run through context.github or do I need to specify them on a per-request basis?

@issue-label-bot

This comment has been minimized.

Copy link

commented Jun 22, 2019

Issue-Label Bot is automatically applying the label question ❓ to this issue, with a confidence of 0.68. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@welcome

This comment has been minimized.

Copy link

commented Jun 22, 2019

Thanks for opening this issue. A contributor should be by to give feedback soon. In the meantime, please check out the contributing guidelines and explore other ways you can get involved.

@gr2m

This comment has been minimized.

Copy link
Contributor

commented Jun 24, 2019

I think there was a way to configure options for the Octokit constructor which then results in context.github but I cannot recall. If you find out, the option is documented here:

http://octokit.github.io/rest.js/#previews

Instead of passing a custom header, you can also pass the special mediaType.previews option, that will make it easier to combine multiple previews

export const listIssues = async (context: Context, { owner, repo, since }) =>
	context.github.paginate(
		context.github.issues.listForRepo.endpoint.merge({
			owner,
			repo,
			state: "all",
			since,
			per_page: 100,
			mediaType: {
				previews: ["squirrel-girl"]
			},
		}),
	);
@faustbrian

This comment has been minimized.

Copy link
Author

commented Jul 3, 2019

Thanks, will just stick with a helper method for now then.

@faustbrian faustbrian closed this Jul 3, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.