codeflash-internal/js/cf-api/scripts/setup-org.ts

18 lines
486 B
TypeScript
Raw Normal View History

[feat] sync org and member using cron job (#2006) fixes cf-795 ## Description - **Description of PR**: Added a new cron job inside the Express server that runs every day at midnight (UTC). This cron job is responsible for syncing organizations, repositories, and member access. It fetches all installations, retrieves members, and applies the required access logic. The job logs the **start time**, **end time**, **duration**, and **status** (success or failure), and sends a detailed summary email via **Resend** to **Saurabh**, with **CC** to **Hesham** and **Sarthak** (additional recipients can be added as needed). --- ## Testing - **Manual Testing**: **Steps to test locally:** 1. Connect to your local database. 2. Reduce the cron interval to **5 minutes** for faster testing. 3. Wait for the cron job to trigger. 4. After it finishes, verify that **organizations**, **repositories**, and **users** are synced correctly. 5. Check your email for the **success summary message**. 6. Run **cf-webapp** and verify your membership in the **Codeflash** org. 7. In the database: - Add yourself as a **member** of another org. - change your role in Codeflash org . 8. Wait for the next cron execution — you should be **removed** from the other org and reverted your role in Codeflash. 9. Throw a **custom error** to verify that the email correctly reports all details (start time, end time, duration, and failure reason). --- Note: we need to review this PR carefully --------- Co-authored-by: mohammed ahmed <64513301+mohammedahmed18@users.noreply.github.com> Co-authored-by: Kevin Turcios <106575910+KRRT7@users.noreply.github.com>
2025-11-26 16:46:45 +00:00
import { syncOrgsWithMembers } from "../github/github-utils.js"
[Feat] Organization (#1888) ## Organization Feature This PR introduces a new **Organization** feature that allows users to: - Create organizations and add members - Manage repositories within organizations - Allow organization members to access and view shared repository data --- ## How to Test ### 1. Setup - Apply the latest **database migrations**. - Build the **common** package, then **pack** and **install** it in both: - `cf-webapp` - `cf-api` ### 2. Create an Organization - You can create an organization **manually** in the database, **or** - Use the **GitHub webhook** to add it automatically. ### 3. Test Scenarios Prepare the following: - **Two users:** - **User A** – has access to the organization and its repositories. - **User B** – a regular user. - **Two repositories:** - One under the **organization**. - One under **User A’s personal account**. ### 4. Verification Steps 1. Log in to **cf-webapp** as **User A**. 2. Confirm both the **personal account** and **organization** appear. 3. Try optimizing code and ensure **statistics** display correctly. 4. Switch between **personal** and **organization** accounts to verify data accuracy. 5. From the **personal account**: - Open a specific repository. - Add a new member by **GitHub username**. - Log in as that member (**User B**) and verify access. 6. From the **organization**: - Add members to the organization by **GitHub username**. - Log in as the added member and confirm they have access to organization repositories. - Update the member’s **role** and ensure changes are applied correctly. --- --------- Co-authored-by: ali <mohammed18200118@gmail.com> Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-10-29 20:05:40 +00:00
import { githubApp } from "../github/github-app.js"
;(async () => {
try {
const orgs = process.argv.slice(2)
if (orgs.length === 0) {
console.error(
"Error: Please provide at least one organization name as a command line argument.",
)
process.exit(1)
}
[feat] sync org and member using cron job (#2006) fixes cf-795 ## Description - **Description of PR**: Added a new cron job inside the Express server that runs every day at midnight (UTC). This cron job is responsible for syncing organizations, repositories, and member access. It fetches all installations, retrieves members, and applies the required access logic. The job logs the **start time**, **end time**, **duration**, and **status** (success or failure), and sends a detailed summary email via **Resend** to **Saurabh**, with **CC** to **Hesham** and **Sarthak** (additional recipients can be added as needed). --- ## Testing - **Manual Testing**: **Steps to test locally:** 1. Connect to your local database. 2. Reduce the cron interval to **5 minutes** for faster testing. 3. Wait for the cron job to trigger. 4. After it finishes, verify that **organizations**, **repositories**, and **users** are synced correctly. 5. Check your email for the **success summary message**. 6. Run **cf-webapp** and verify your membership in the **Codeflash** org. 7. In the database: - Add yourself as a **member** of another org. - change your role in Codeflash org . 8. Wait for the next cron execution — you should be **removed** from the other org and reverted your role in Codeflash. 9. Throw a **custom error** to verify that the email correctly reports all details (start time, end time, duration, and failure reason). --- Note: we need to review this PR carefully --------- Co-authored-by: mohammed ahmed <64513301+mohammedahmed18@users.noreply.github.com> Co-authored-by: Kevin Turcios <106575910+KRRT7@users.noreply.github.com>
2025-11-26 16:46:45 +00:00
await syncOrgsWithMembers(githubApp, orgs)
[Feat] Organization (#1888) ## Organization Feature This PR introduces a new **Organization** feature that allows users to: - Create organizations and add members - Manage repositories within organizations - Allow organization members to access and view shared repository data --- ## How to Test ### 1. Setup - Apply the latest **database migrations**. - Build the **common** package, then **pack** and **install** it in both: - `cf-webapp` - `cf-api` ### 2. Create an Organization - You can create an organization **manually** in the database, **or** - Use the **GitHub webhook** to add it automatically. ### 3. Test Scenarios Prepare the following: - **Two users:** - **User A** – has access to the organization and its repositories. - **User B** – a regular user. - **Two repositories:** - One under the **organization**. - One under **User A’s personal account**. ### 4. Verification Steps 1. Log in to **cf-webapp** as **User A**. 2. Confirm both the **personal account** and **organization** appear. 3. Try optimizing code and ensure **statistics** display correctly. 4. Switch between **personal** and **organization** accounts to verify data accuracy. 5. From the **personal account**: - Open a specific repository. - Add a new member by **GitHub username**. - Log in as that member (**User B**) and verify access. 6. From the **organization**: - Add members to the organization by **GitHub username**. - Log in as the added member and confirm they have access to organization repositories. - Update the member’s **role** and ensure changes are applied correctly. --- --------- Co-authored-by: ali <mohammed18200118@gmail.com> Co-authored-by: Sarthak Agarwal <sarthak.saga@gmail.com>
2025-10-29 20:05:40 +00:00
console.log("✅ DONE")
} catch (error) {
console.error(error)
}
})()