Skip to content

Commit

Permalink
Fix GitHub Q&A sample not working with some repos (#2117)
Browse files Browse the repository at this point in the history
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
Address item: #2041

### Description
1. Fill in the required header fields by default.
2. Update ReadMe to include private repo access information.


<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#dev-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
  • Loading branch information
TaoChenOSU committed Jul 21, 2023
1 parent 53a3a84 commit 3cc4a4d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions samples/apps/github-qna-webapp-react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ only content extracted from markdown files.
> [!CAUTION]
> Each function will call Open AI which will use tokens that you will be billed for.
## Working with private repositories
The GitHub Repo Q&A Bot sample allows you to pull in data from a private GitHub repo. To do so, you must create a [fine-grained personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-fine-grained-personal-access-token) if you have not already. The token must have access to the repository you are trying to pull data from as well as read access to the Contents of the repository:
![Alt text](contents-read-access.png)


## Next Steps

Create Skills and SK functions: Check out the [documentation](https://aka.ms/sk/learn)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions samples/dotnet/KernelHttpServer/Plugins/GitHubPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ public GitHubPlugin(IKernel kernel, ILogger<GitHubPlugin>? logger = null)
this._logger.LogDebug("Downloading {RepoBundle}", repoBundle);

var headers = new Dictionary<string, string>();
headers.Add("X-GitHub-Api-Version", "2022-11-28");
headers.Add("Accept", "application/vnd.github+json");
headers.Add("User-Agent", "msft-semantic-kernel-sample");
if (!string.IsNullOrEmpty(patToken))
{
this._logger.LogDebug("Access token detected, adding authorization headers");
headers.Add("Authorization", $"Bearer {patToken}");
headers.Add("X-GitHub-Api-Version", "2022-11-28");
headers.Add("Accept", "application/vnd.github+json");
headers.Add("User-Agent", "msft-semantic-kernel-sample");
}

await this.DownloadToFileAsync(repoBundle, headers, filePath, cancellationToken);
Expand Down

0 comments on commit 3cc4a4d

Please sign in to comment.