Skip to content

Commit

Permalink
fix: direct links to install apps on correct repository, add toc
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Mar 25, 2021
1 parent f8616e2 commit 8aec6cb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
17 changes: 15 additions & 2 deletions create-octokit-project.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function main() {
});

const {
data: { login, name, email, blog: website },
data: { id: userId, login, name, email, blog: website },
} = await octokit.request("GET /user");

try {
Expand All @@ -102,6 +102,14 @@ async function main() {
const [owner, repo] = answers.repository.split("/");
const isUserRepo = answers.repository.startsWith(login);

let ownerId = userId;
if (!isUserRepo) {
const { data } = await octokit.request("GET /orgs/{org}", {
org: owner,
});
ownerId = data.id;
}

// create project folder and chdir into it
console.log(`Creating ${answers.path}`);
await mkdir(answers.path, { recursive: true });
Expand Down Expand Up @@ -145,7 +153,9 @@ async function main() {
await command("git add .github/ISSUE_TEMPLATE");
await command("git commit -m 'docs(ISSUE_TEMPLATES): initial version'");

await createRepository(octokit, {
const {
data: { id: repositoryId },
} = await createRepository(octokit, {
isUserRepo,
owner,
repo,
Expand All @@ -169,6 +179,8 @@ async function main() {
await createPullRequest(octokit, {
owner,
repo,
ownerId,
repositoryId,
});

await createPackageJson(answers);
Expand Down Expand Up @@ -423,6 +435,7 @@ async function main() {
await command(`git commit README.md -m 'docs(README): badges'`);

await createReadme({
useOctokitOrg,
addBadges: true,
addUsage: true,
repo,
Expand Down
15 changes: 11 additions & 4 deletions lib/create-pull-request.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
module.exports = createPullRequest;

async function createPullRequest(octokit, { owner, repo }) {
async function createPullRequest(
octokit,
{ owner, repo, ownerId, repositoryId }
) {
let body = `- [ ] Implement features. Create separate \`feat: ...\` commits for each feature of the initial version
- [ ] 100% test coverage
- [ ] Install https://github.com/apps/wip
- [ ] Install https://github.com/apps/renovate
`;

if (owner !== "octokit") {
if (owner === "octokit") {
body += `- [ ] [Install the WIP app](https://github.com/apps/wip/installations/new/permissions?suggested_target_id=${ownerId}&repository_ids[]=${repositoryId})
- [ ] [Install the Renovate app](https://github.com/apps/renovate/installations/new/permissions?suggested_target_id=${ownerId}&repository_ids[]=${repositoryId})
- [ ] [Install the Octokit JS Board app](https://github.com/apps/octokit-js-project-board/installations/new/permissions?suggested_target_id=${ownerId}&repository_ids[]=${repositoryId})
- [ ] [Install the prettier-toc-me app](https://github.com/apps/prettier-toc-me/installations/new/permissions?suggested_target_id=${ownerId}&repository_ids[]=${repositoryId})
`;
} else {
body += `- [ ] Create npm token at \`https://www.npmjs.com/settings/<your npm username>/tokens/create\` (with "Read and Publish" selected) and add it as \`NPM_TOKEN\` at Then create secret at https://github.com/${owner}/${repo}/settings/secrets`;
}

Expand Down
12 changes: 12 additions & 0 deletions lib/create-readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ async function createReadme({
packageName,
addWip,
addBadges,
useOctokitOrg,
addUsage,
supportsBrowsers,
supportsNode,
Expand Down Expand Up @@ -42,6 +43,17 @@ async function createReadme({
}

if (addUsage) {
if (useOctokitOrg) {
content += `<details>
<summary>Table of contents</summary>
<!-- toc -->
</details>
`;
}

const UsageTitle = octokitUsageExample ? "Standalone usage" : "usage";
content += `## ${UsageTitle}
Expand Down
5 changes: 2 additions & 3 deletions lib/create-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ async function createRepository(
};

if (isUserRepo) {
await octokit.request("POST /user/repos", createRepoOptions);
return;
return octokit.request("POST /user/repos", createRepoOptions);
}

await octokit.request("POST /orgs/{org}/repos", {
return octokit.request("POST /orgs/{org}/repos", {
org: owner,
...createRepoOptions,
});
Expand Down

0 comments on commit 8aec6cb

Please sign in to comment.