Skip to content

Commit

Permalink
enforce uniqueness of snip names across repos
Browse files Browse the repository at this point in the history
  • Loading branch information
axfelix committed Nov 8, 2024
1 parent 8b225d0 commit eaa78df
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ class Sync {
// Get repository details and file paths.
const repositories = await this.getRepos();
// Search each origin file and scrape the snippets
const snippets = await this.extractSnippets(repositories);
try {
const snippets = await this.extractSnippets(repositories);
} catch (e) {
console.error(e);
await this.cleanUp();
process.exit(1);
}
// Get the infos (name, path) of all the files in the target directories
let targetFiles = await this.getTargetFilesInfos();
// Add the lines of each file
Expand Down Expand Up @@ -317,6 +323,12 @@ class Sync {
capture = true;
const id = extractReadID(line);
const snip = new Snippet(id, ext, owner, repo, ref, item);
// check for uniqueness of snippet ids before pushing
for (const existingSnip of snippets) {
if (existingSnip.id == id) {
throw new Error('Snippet name exists in multiple repository sources.');
}
}
fileSnips.push(snip);
}
});
Expand Down

0 comments on commit eaa78df

Please sign in to comment.