Skip to content

Commit

Permalink
Update schema.graphql (#27)
Browse files Browse the repository at this point in the history
* Update schema.graphql

* chore: update schema

* chore: update schema

* chore: change cosmo.yaml

* chore: update action

* chore: update action

* chore: update action

* chore: update action
  • Loading branch information
JivusAyrus authored Aug 20, 2024
1 parent 3356b8a commit 12670c2
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 18 deletions.
45 changes: 37 additions & 8 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

44 changes: 42 additions & 2 deletions src/github.ts → src/githubFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export const normalizeSeparators = (p: string): string => {
p = p.replace(/\//g, '\\');

// Remove redundant slashes
const isUnc = /^\\\\+[^\\]/.test(p); // e.g. \\hello
p = (isUnc ? '\\' : '') + p.replace(/\\\\+/g, '\\'); // preserve leading \\ for UNC
const isUnc = /^\\\\+[^\\]/.test(p);
p = (isUnc ? '\\' : '') + p.replace(/\\\\+/g, '\\');
} else {
// Remove redundant slashes on Linux/macOS
p = p.replace(/\/\/+/g, '/');
Expand Down Expand Up @@ -166,3 +166,43 @@ export const getRemovedGraphQLFilesInLastCommit = async ({

return removedGraphQLFiles;
};

export const hasCosmoConfigChangedInLastCommit = async ({
githubToken,
prNumber,
}: {
githubToken: string;
prNumber: number;
}): Promise<boolean> => {
const octokit = github.getOctokit(githubToken);

// Get the list of commits in the pull request
const commits = await octokit.rest.pulls.listCommits({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: prNumber,
});

// Get the last commit
const lastCommit = commits.data.at(-1);
if (!lastCommit) {
return false;
}
const lastCommitSha = lastCommit.sha;

// Get the list of files in the last commit
const commitFiles = await octokit.rest.repos.getCommit({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
ref: lastCommitSha,
});
if (!commitFiles.data.files) {
return false;
}

// Filter out the files that were removed
const modifiedFiles = commitFiles.data.files?.filter((file) => file.status === 'modified');
const modifiedFilePaths = modifiedFiles.map((file) => file.filename);

return modifiedFilePaths.includes('.github/cosmo.yaml');
};
2 changes: 2 additions & 0 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type Inputs = {
namespace: string;
featureFlags: FeatureFlag[];
subgraphs: Subgraph[];
configPath: string;
};

export const getInputs = (): Inputs | undefined => {
Expand Down Expand Up @@ -99,5 +100,6 @@ export const getInputs = (): Inputs | undefined => {
namespace,
featureFlags,
subgraphs,
configPath,
};
};
19 changes: 12 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { SubgraphCommandJsonOutput, WhoAmICommandJsonOutput } from 'wgc/dist/cor
import { Context } from '@actions/github/lib/context.js';
import { Inputs, getInputs } from './inputs.js';
import { addComment } from './utils.js';
import { getChangedFilesFromGithubAPI, getFilteredChangedFiles, getRemovedGraphQLFilesInLastCommit } from './github.js';
import {
getChangedFilesFromGithubAPI,
getFilteredChangedFiles,
getRemovedGraphQLFilesInLastCommit,
hasCosmoConfigChangedInLastCommit,
} from './githubFiles.js';

/**
* The main function for the action.
Expand Down Expand Up @@ -45,18 +50,18 @@ export async function run(): Promise<void> {
});

if (inputs.actionType === 'update') {
const isCosmoConfigChanged =
getFilteredChangedFiles({
allDiffFiles: changedFiles,
filePatterns: ['cosmo.yaml'],
}).length > 0;
const isCosmoConfigChanged = await hasCosmoConfigChangedInLastCommit({
githubToken: inputs.githubToken,
prNumber,
});

if (isCosmoConfigChanged) {
const octokit = github.getOctokit(inputs.githubToken);
await octokit.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: `### ❌ The Cosmo config file is changed. Please close and reopen the pr.`,
body: `The Cosmo configuration file has been modified. Please close and reopen the pull request. Failing to do so may cause the feature flag to function improperly.`,
});
core.setFailed('Cosmo config file is changed. Please close and reopen the pr.');
return;
Expand Down

0 comments on commit 12670c2

Please sign in to comment.