From 122d6ffe604eb2980d9d2b6e956520991b125300 Mon Sep 17 00:00:00 2001 From: Salman Ibrahim Date: Tue, 21 Nov 2023 23:08:10 +0500 Subject: [PATCH 1/7] make project open to contributions --- .env.example | 1 - .github/workflows/build.yml | 30 +++++++++++++++++++++++++--- .github/workflows/deploy.yml | 9 +++------ src/components/StatusBar.tsx | 38 ++++++++++++++++-------------------- 4 files changed, 47 insertions(+), 31 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index f974114..0000000 --- a/.env.example +++ /dev/null @@ -1 +0,0 @@ -VITE_GITHUB_ACCESS_TOKEN=YOUR_GITHUB_ACCESS_TOKEN \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a32be21..db90b34 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,9 +12,6 @@ jobs: build: runs-on: ubuntu-latest - env: - VITE_GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - name: Checkout code uses: actions/checkout@v3 @@ -27,5 +24,32 @@ jobs: - name: Install dependencies run: npm install + - name: Lint code + run: npm run lint + - name: Build app run: npm run build + + - name: Check for Lint/Build Errors + if: failure() + run: | + if [ -s "$(git diff --name-only ${{ github.sha }} ${{ github.event.before }})" ]; then + echo "Linting or build errors detected." + curl -X POST \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \ + -d '{"body": "Linting or build errors detected. Please review and address the issues before merging."}' + exit 1 + fi + - name: If No Errors, Merge + if: success() + run: | + if [ -z "$(git diff --name-only ${{ github.sha }} ${{ github.event.before }})" ]; then + echo "No linting or build errors detected. Merging." + curl -X PUT \ + -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}/merge \ + -d '{"commit_title": "You Rock Thank you for your contribution! One core maintainer will review your changes and merge them if they are approved."}' + fi diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index cb4fe81..6ef1a53 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,9 +1,9 @@ name: Deploy to GitHub Pages 🚀 on: - push: - branches: - - main + push: + branches: + - main permissions: contents: read @@ -21,9 +21,6 @@ jobs: url: ${{steps.deployment.outputs.page_url}} runs-on: ubuntu-latest - env: - VITE_GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - name: Checkout uses: actions/checkout@v3 diff --git a/src/components/StatusBar.tsx b/src/components/StatusBar.tsx index 324e665..3bed4bb 100644 --- a/src/components/StatusBar.tsx +++ b/src/components/StatusBar.tsx @@ -3,17 +3,10 @@ import Tooltip from "./Elements/Tooltip" import { Chrome, Copyright, Eye, Fullscreen, GitBranch, GitFork, Github, Hash, Scale, Star } from "lucide-react" import values from "@/values/strings.json" -type License = { - key: string, - name: string, - url: string, -} - type RepositoryData = { stargazers_count: number, forks_count: number, watchers_count: number, - license: License, } function StatusBar() { @@ -24,15 +17,14 @@ function StatusBar() { const fetchRepositoryData = async () => { // make fetch request with above using fetch api // Add X-GitHub-Api-Version: 2022-11-28 header to request - const headers = new Headers() - headers.append('Accept', 'application/vnd.github.v3+json') - headers.append('X-GitHub-Api-Version', '2022-11-28') - headers.append('Authorization', `token ${import.meta.env.VITE_GITHUB_ACCESS_TOKEN}`) - const response = await fetch('https://api.github.com/repos/salman-ibrahim/codefolio', { - headers: headers - }) + // const endpoint = 'https://api.github.com/repos/salman-ibrahim/codefolio' + const endpoint = 'https://api.github.com/search/repositories?q=salman-ibrahim/codefolio' + const response = await fetch(endpoint) const data = await response.json() - setRepositoryData(data) + + // Filter from all the results where item.full_name === salman-ibrahim/codefolio + const repo = data.items.filter((item: any) => item.full_name === 'salman-ibrahim/codefolio')[0] + setRepositoryData(repo) } useEffect(() => { @@ -111,12 +103,16 @@ function StatusBar() { CSS - -
- - MIT -
-
+ { + values.links.license !== undefined + && + +
+ + MIT +
+
+ }
From c4fc1c858fd08480f9bf90139caf03202a6c2713 Mon Sep 17 00:00:00 2001 From: Salman Ibrahim Date: Tue, 21 Nov 2023 23:43:29 +0500 Subject: [PATCH 2/7] ... --- .github/workflows/build.yml | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index db90b34..8fb63f3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,16 +32,12 @@ jobs: - name: Check for Lint/Build Errors if: failure() - run: | - if [ -s "$(git diff --name-only ${{ github.sha }} ${{ github.event.before }})" ]; then - echo "Linting or build errors detected." - curl -X POST \ - -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.number }}/comments \ - -d '{"body": "Linting or build errors detected. Please review and address the issues before merging."}' - exit 1 - fi + uses: actions/github-script@v6 + with: + script: | + core.info("Linting or build errors detected. Please fix them and push again.") + core.setFailed("Linting or build errors detected. Please fix them and push again.") + - name: If No Errors, Merge if: success() run: | From 9a3611ab8319ec2e60dee38a4bb291672513ad84 Mon Sep 17 00:00:00 2001 From: Salman Ibrahim Date: Tue, 21 Nov 2023 23:45:59 +0500 Subject: [PATCH 3/7] ... --- .github/workflows/build.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8fb63f3..b3b9536 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,8 +35,13 @@ jobs: uses: actions/github-script@v6 with: script: | - core.info("Linting or build errors detected. Please fix them and push again.") core.setFailed("Linting or build errors detected. Please fix them and push again.") + github.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "Linting or build errors detected. Please fix them and push again." + }) - name: If No Errors, Merge if: success() From 72068f7b419aeec3153d7b335a5a3c7fc5a086ad Mon Sep 17 00:00:00 2001 From: Salman Ibrahim Date: Tue, 21 Nov 2023 23:47:44 +0500 Subject: [PATCH 4/7] ... --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b3b9536..482fffc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,7 +36,7 @@ jobs: with: script: | core.setFailed("Linting or build errors detected. Please fix them and push again.") - github.issues.createComment({ + github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, From 3bf780e1a2efded896fe6afa705102cce1ae480f Mon Sep 17 00:00:00 2001 From: Salman Ibrahim Date: Tue, 21 Nov 2023 23:59:58 +0500 Subject: [PATCH 5/7] ... --- .github/workflows/build.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 482fffc..b7ff272 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,19 @@ jobs: issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: "Linting or build errors detected. Please fix them and push again." + body: "Looks like you missed something Linting or build errors detected. Please fix them and push again." + }) + github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: "Linting and Build Errors", + head_sha: context.sha, + status: "completed", + conclusion: "failure", + output: { + title: "Linting or Build Errors", + summary: "Linting/Build errors detected. Please fix them and push again." + } }) - name: If No Errors, Merge From a4a375579868f46000824e88d9f66c0ae1fc7b94 Mon Sep 17 00:00:00 2001 From: Salman Ibrahim Date: Wed, 22 Nov 2023 00:13:58 +0500 Subject: [PATCH 6/7] ... --- .github/workflows/build.yml | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b7ff272..ddfb5de 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,23 @@ jobs: runs-on: ubuntu-latest steps: + + - name: Build Checks + uses: actions/github-script@v6 + with: + script: | + github.rest.checks.create({ + name: 'Build Checks', + head_sha: context.sha, + status: 'in_progress', + started_at: new Date().toISOString(), + output: { + title: 'Build Checks', + summary: 'Build Checks', + }, + owner: context.repo.owner, + repo: context.repo.repo + }) - name: Checkout code uses: actions/checkout@v3 @@ -30,7 +47,7 @@ jobs: - name: Build app run: npm run build - - name: Check for Lint/Build Errors + - name: Checks Failed if: failure() uses: actions/github-script@v6 with: @@ -42,20 +59,8 @@ jobs: repo: context.repo.repo, body: "Looks like you missed something Linting or build errors detected. Please fix them and push again." }) - github.rest.checks.create({ - owner: context.repo.owner, - repo: context.repo.repo, - name: "Linting and Build Errors", - head_sha: context.sha, - status: "completed", - conclusion: "failure", - output: { - title: "Linting or Build Errors", - summary: "Linting/Build errors detected. Please fix them and push again." - } - }) - - name: If No Errors, Merge + - name: All Checks Passed if: success() run: | if [ -z "$(git diff --name-only ${{ github.sha }} ${{ github.event.before }})" ]; then From 487888ed76e3843da0007e22750ed42cfb49479f Mon Sep 17 00:00:00 2001 From: Salman Ibrahim Date: Wed, 22 Nov 2023 00:21:41 +0500 Subject: [PATCH 7/7] open source ready --- .github/workflows/build.yml | 37 ++++++++++-------------------------- src/components/StatusBar.tsx | 3 ++- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ddfb5de..20674ec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,23 +13,6 @@ jobs: runs-on: ubuntu-latest steps: - - - name: Build Checks - uses: actions/github-script@v6 - with: - script: | - github.rest.checks.create({ - name: 'Build Checks', - head_sha: context.sha, - status: 'in_progress', - started_at: new Date().toISOString(), - output: { - title: 'Build Checks', - summary: 'Build Checks', - }, - owner: context.repo.owner, - repo: context.repo.repo - }) - name: Checkout code uses: actions/checkout@v3 @@ -57,17 +40,17 @@ jobs: issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: "Looks like you missed something Linting or build errors detected. Please fix them and push again." + body: "⚠️ Looks like you missed something Linting or build errors detected. Please fix them and push again." }) - name: All Checks Passed if: success() - run: | - if [ -z "$(git diff --name-only ${{ github.sha }} ${{ github.event.before }})" ]; then - echo "No linting or build errors detected. Merging." - curl -X PUT \ - -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.number }}/merge \ - -d '{"commit_title": "You Rock Thank you for your contribution! One core maintainer will review your changes and merge them if they are approved."}' - fi + uses: actions/github-script@v6 + with: + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: "Kudos! All checks passed. 🎉 Thanks for contributing to the project, one of our maintainers will review your changes soon." + }) diff --git a/src/components/StatusBar.tsx b/src/components/StatusBar.tsx index 3bed4bb..fc48de7 100644 --- a/src/components/StatusBar.tsx +++ b/src/components/StatusBar.tsx @@ -7,6 +7,7 @@ type RepositoryData = { stargazers_count: number, forks_count: number, watchers_count: number, + full_name: string } function StatusBar() { @@ -23,7 +24,7 @@ function StatusBar() { const data = await response.json() // Filter from all the results where item.full_name === salman-ibrahim/codefolio - const repo = data.items.filter((item: any) => item.full_name === 'salman-ibrahim/codefolio')[0] + const repo = data.items.filter((item: RepositoryData) => item.full_name === 'salman-ibrahim/codefolio')[0] setRepositoryData(repo) }