Skip to content
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 Sep 20, 2025
4f9b2f7
Add initial client for repository properties
mbg Sep 19, 2025
3b00d03
Load repository properties and store them in the `Config`
mbg Sep 19, 2025
6150aff
Add and use `QuerySpec` type
mbg Sep 19, 2025
ed216a0
Include queries from repo properties in `AugmentationProperties`
mbg Sep 20, 2025
781a65a
Use appropriate error message in `parseQueriesFromInput` for repo pro…
mbg Sep 20, 2025
1bfb67d
Refactor combining queries into its own function
mbg Sep 20, 2025
d14a212
Include repo property queries in `combineQueries`
mbg Sep 20, 2025
c7eb488
Add tests
mbg Sep 20, 2025
d46a178
Sort `queries` array in `check-codescanning-config`
mbg Sep 22, 2025
6bb4ad3
Update .github/actions/check-codescanning-config/index.ts
mbg Sep 22, 2025
54746c8
Fix `expected-config-file-contents`
mbg Sep 22, 2025
889d482
Add logging to `combineQueries`
mbg Sep 22, 2025
05310c6
Ignore repository property query config if CQ-only analysis
mbg Sep 22, 2025
b4f966a
Add FF to control whether to fetch repository properties
mbg Sep 22, 2025
40262b1
Add `getRepositoryProperties` to `api-client`, for easier mocking
mbg Sep 23, 2025
07920e8
Fix using `keys` instead of `values`
mbg Sep 23, 2025
7f73f8c
Add unit tests for `properties` module
mbg Sep 23, 2025
0a75581
Check that we are on dotcom
mbg Sep 23, 2025
205b6ba
Rebuild
mbg Sep 23, 2025
4178e15
Only disable `loadPropertiesFromApi` on GHES
mbg Sep 23, 2025
54bbe82
Always log when queries are configured in the repository properties
mbg Sep 23, 2025
5a4aa83
Always log when combining queries is disabled in the repo properties
mbg Sep 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add initial client for repository properties
  • Loading branch information
mbg committed Sep 20, 2025
commit 4f9b2f7f065cbd60b389893b55fda99565816340
84 changes: 84 additions & 0 deletions src/feature-flags/properties.ts
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));
Comment thread
mbg marked this conversation as resolved.
Outdated
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}`,
);
}
}