Skip to content

Commit

Permalink
Relocate repo-scoped custom properties calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwilcox committed Nov 14, 2023
1 parent 00eb7c2 commit ce034b0
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 207 deletions.
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ FROM $IMAGE_NAME AS build

ARG NPM_TOKEN

# Make Git available for NPM and rsync in the build image
RUN tdnf -y update --quiet && \
tdnf -y install ca-certificates git --quiet && \
tdnf clean all --quiet
RUN tdnf -y update --quiet

# We used to also make Git available for NPM and rsync in build
# tdnf clean all --quiet && \
# tdnf -y install ca-certificates git --quiet && \

WORKDIR /build

Expand Down
48 changes: 2 additions & 46 deletions business/organizationProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { CreateError } from '../transitional';
import { AppPurpose, AppPurposeTypes } from '../lib/github/appPurposes';
import {
CacheDefault,
createCacheOptions,
createPagedCacheOptions,
getMaxAgeSeconds,
getPageSize,
Expand All @@ -40,7 +39,7 @@ export type OrganizationCustomPropertyEntity = {
allowed_values?: string[];
};

type SetPropertyValue = {
export type OrganizationCustomPropertySetPropertyValue = {
property_name: string;
value: string;
};
Expand All @@ -66,32 +65,6 @@ export class OrganizationProperties {
return getAuthorizationHeader;
}

async getRepositoryCustomProperties(
repositoryName: string,
options?: ICacheOptionsWithPurpose
): Promise<Record<string, string>> {
options = options || {};
const operations = throwIfNotGitHubCapable(this.operations);
const { github } = operations;
const purpose = popPurpose(options, this._defaultPurpose);
const parameters = {
owner: this.organization.name,
repo: repositoryName,
};
const cacheOptions = createCacheOptions(operations, options);
try {
const responseArray = await github.request(
this.authorize(purpose),
'GET /repos/:owner/:repo/properties/values',
parameters,
cacheOptions
);
return symbolizeApiResponse(arrayToSetProperties(responseArray));
} catch (error) {
throw error;
}
}

async getCustomProperties(
options?: PagedCacheOptionsWithPurpose
): Promise<OrganizationCustomPropertyEntity[]> {
Expand Down Expand Up @@ -187,15 +160,6 @@ export class OrganizationProperties {
return res.properties;
}

createOrUpdateRepositoryProperties(
repositoryName: string,
propertiesAndValues: Record<string, string>,
purpose?: AppPurposeTypes
): Promise<void> {
const names = [repositoryName];
return this.createOrUpdateRepositoriesProperties(names, propertiesAndValues, purpose);
}

async createOrUpdateRepositoriesProperties(
organizationRepositoryNames: string[],
propertiesAndValues: Record<string, string>,
Expand Down Expand Up @@ -223,7 +187,7 @@ export class OrganizationProperties {

function setPropertiesRecordToArray(propertiesAndValues: Record<string, string>) {
const keys = Object.getOwnPropertyNames(propertiesAndValues);
const properties: SetPropertyValue[] = [];
const properties: OrganizationCustomPropertySetPropertyValue[] = [];
for (const key of keys) {
properties.push({
property_name: key,
Expand All @@ -232,11 +196,3 @@ function setPropertiesRecordToArray(propertiesAndValues: Record<string, string>)
}
return properties;
}

function arrayToSetProperties(properties: SetPropertyValue[]) {
const propertiesAndValues: Record<string, string> = {};
for (const property of properties) {
propertiesAndValues[property.property_name] = property.value;
}
return propertiesAndValues;
}
13 changes: 13 additions & 0 deletions business/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { RepositoryPullRequest } from './repositoryPullRequest';
import { ErrorHelper } from '../transitional';
import { augmentInertiaPreview, RepositoryProject } from './repositoryProject';
import { RepositoryInvitation } from './repositoryInvitation';
import { RepositoryProperties } from './repositoryProperties';

interface IRepositoryMoments {
created?: moment.Moment;
Expand Down Expand Up @@ -219,6 +220,7 @@ export class Repository {
private _operations: IOperationsInstance;

private _organization: Organization;
private _customProperties: RepositoryProperties;

private _name: string;

Expand Down Expand Up @@ -388,6 +390,17 @@ export class Repository {
this._operations = operations;
}

get customProperties() {
if (!this._customProperties) {
this._customProperties = new RepositoryProperties(
this,
this._operations,
this._getSpecificAuthorizationHeader.bind(this)
);
}
return this._customProperties;
}

get moment(): IRepositoryMoments {
if (!this._moments) {
this._moments = {
Expand Down
31 changes: 0 additions & 31 deletions features/graphTeamSync.ts

This file was deleted.

4 changes: 2 additions & 2 deletions middleware/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ export default async function initialize(
const containerPurpose = executionEnvironment.isJob
? 'job'
: applicationProfile.webServer
? 'web application'
: 'application';
? 'web application'
: 'application';
if (executionEnvironment.entrypointName) {
debug(`${containerPurpose} name: ${executionEnvironment.entrypointName}`);
}
Expand Down
Loading

0 comments on commit ce034b0

Please sign in to comment.