-
Notifications
You must be signed in to change notification settings - Fork 451
Add support for the repository properties API #3126
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
96ca55b
Ava: Run all tests in `src/` directory
mbg 4f9b2f7
Add initial client for repository properties
mbg 3b00d03
Load repository properties and store them in the `Config`
mbg 6150aff
Add and use `QuerySpec` type
mbg ed216a0
Include queries from repo properties in `AugmentationProperties`
mbg 781a65a
Use appropriate error message in `parseQueriesFromInput` for repo pro…
mbg 1bfb67d
Refactor combining queries into its own function
mbg d14a212
Include repo property queries in `combineQueries`
mbg c7eb488
Add tests
mbg d46a178
Sort `queries` array in `check-codescanning-config`
mbg 6bb4ad3
Update .github/actions/check-codescanning-config/index.ts
mbg 54746c8
Fix `expected-config-file-contents`
mbg 889d482
Add logging to `combineQueries`
mbg 05310c6
Ignore repository property query config if CQ-only analysis
mbg b4f966a
Add FF to control whether to fetch repository properties
mbg 40262b1
Add `getRepositoryProperties` to `api-client`, for easier mocking
mbg 07920e8
Fix using `keys` instead of `values`
mbg 7f73f8c
Add unit tests for `properties` module
mbg 0a75581
Check that we are on dotcom
mbg 205b6ba
Rebuild
mbg 4178e15
Only disable `loadPropertiesFromApi` on GHES
mbg 54bbe82
Always log when queries are configured in the repository properties
mbg 5a4aa83
Always log when combining queries is disabled in the repo properties
mbg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add initial client for repository properties
- Loading branch information
commit 4f9b2f7f065cbd60b389893b55fda99565816340
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { getApiClient } from "../api-client"; | ||
| import { Logger } from "../logging"; | ||
| import { RepositoryNwo } from "../repository"; | ||
|
|
||
| /** | ||
| * Enumerates repository property names that have some meaning to us. | ||
| */ | ||
| export enum RepositoryPropertyName {} | ||
|
|
||
| /** | ||
| * A repository property has a name and a value. | ||
| */ | ||
| export interface RepositoryProperty { | ||
| property_name: string; | ||
| value: string; | ||
| } | ||
|
|
||
| /** | ||
| * The API returns a list of `RepositoryProperty` objects. | ||
| */ | ||
| type GitHubPropertiesResponse = RepositoryProperty[]; | ||
|
|
||
| /** | ||
| * A partial mapping from `RepositoryPropertyName` to values. | ||
| */ | ||
| export type RepositoryProperties = Partial< | ||
| Record<RepositoryPropertyName, string> | ||
| >; | ||
|
|
||
| /** | ||
| * Retrieves all known repository properties from the API. | ||
| * | ||
| * @param logger The logger to use. | ||
| * @param repositoryNwo Information about the repository for which to load properties. | ||
| * @returns Returns a partial mapping from `RepositoryPropertyName` to values. | ||
| */ | ||
| export async function loadPropertiesFromApi( | ||
| logger: Logger, | ||
| repositoryNwo: RepositoryNwo, | ||
| ): Promise<RepositoryProperties> { | ||
| try { | ||
| const response = await getApiClient().request( | ||
| "GET /repos/:owner/:repo/properties/values", | ||
| { | ||
| owner: repositoryNwo.owner, | ||
| repo: repositoryNwo.repo, | ||
| }, | ||
| ); | ||
| const remoteProperties = response.data as GitHubPropertiesResponse; | ||
|
|
||
| if (!Array.isArray(remoteProperties)) { | ||
| throw new Error( | ||
| `Expected repository properties API to return an array, but got: ${JSON.stringify(response.data)}`, | ||
| ); | ||
| } | ||
|
|
||
| const knownProperties = new Set(Object.keys(RepositoryPropertyName)); | ||
| const properties: RepositoryProperties = {}; | ||
| for (const property of remoteProperties) { | ||
| if (property.property_name === undefined) { | ||
| throw new Error( | ||
| `Expected property object to have a 'property_name', but got: ${JSON.stringify(property)}`, | ||
| ); | ||
| } | ||
|
|
||
| if (knownProperties.has(property.property_name)) { | ||
| properties[property.property_name] = property.value; | ||
| } | ||
| } | ||
|
|
||
| logger.debug("Loaded the following values for the repository properties:"); | ||
| for (const [property, value] of Object.entries(properties).sort( | ||
| ([nameA], [nameB]) => nameA.localeCompare(nameB), | ||
| )) { | ||
| logger.debug(` ${property}: ${value}`); | ||
| } | ||
|
|
||
| return properties; | ||
| } catch (e) { | ||
| throw new Error( | ||
| `Encountered an error while trying to determine repository properties: ${e}`, | ||
| ); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.