MCPcopy Create free account
hub / github.com/angular/dev-infra / updateRepoWithFiles

Function updateRepoWithFiles

github-actions/org-file-sync/lib/main.ts:68–112  ·  view source on GitHub ↗

* Update the target repo to ensure the provided golden file contents are used for the files * with the same path in the repo.

(github: Octokit, repo: string, goldenFiles: Files)

Source from the content-addressed store, hash-verified

66 * with the same path in the repo.
67 */
68async function updateRepoWithFiles(github: Octokit, repo: string, goldenFiles: Files) {
69 core.startGroup(`Update files in "${repo}" repo`);
70 /** The current files, or lack of files, for synchronizing in target repo. */
71 const repoFiles = await getFilesForRepo(github, repo);
72
73 for (let [path, goldenFile] of goldenFiles.entries()) {
74 // If the golden file does not exist, we have nothing to syncronize.
75 if (goldenFile === null) {
76 continue;
77 }
78 /** The target repository's File for the path. */
79 const repoFile = repoFiles.get(path) || null;
80 /** The SHA of the last time the file was updated in the target repo. */
81 let repoSha: string | undefined = undefined;
82 /** The current content of the file in the target repo. */
83 let repoFileContent: string | undefined = undefined;
84
85 // If the repo file is null, there is not previous information to use for comparisons
86 if (repoFile !== null) {
87 repoSha = repoFile.sha;
88 repoFileContent = repoFile.content;
89 }
90
91 if (repoFileContent !== goldenFile.content) {
92 core.info(`Updating "${path}" in "${repo}" repo`);
93 try {
94 await github.repos.createOrUpdateFileContents({
95 content: goldenFile.content,
96 owner: context.repo.owner,
97 repo,
98 path,
99 message: `build: update \`${path}\` to match the content of \`${context.repo.owner}/${context.repo.repo}\``,
100 // The SHA of the previous file content change is used if an update is occuring.
101 sha: repoSha,
102 });
103 } catch (e) {
104 core.info(`Failed to update "${path}"`);
105 console.error(e);
106 }
107 } else {
108 core.info(`"${path}" is already in sync`);
109 }
110 }
111 core.endGroup();
112}
113
114async function main() {
115 const github = new Octokit({auth: await getAuthTokenFor(ANGULAR_ROBOT)});

Callers 1

mainFunction · 0.85

Calls 4

getFilesForRepoFunction · 0.85
entriesMethod · 0.45
getMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected