Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Staging #226

Merged
merged 22 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0626f2c
Create Code Analysis Job: get repo, create projects, pull/clone, scan
rjkoh Sep 18, 2024
fd25876
Code Analysis Model, get metrics and save
rjkoh Sep 19, 2024
8345eb5
style fixing
rjkoh Sep 19, 2024
4bcfa89
update imports and cron schedule
rjkoh Sep 21, 2024
07a32e6
Update course schema with Trofos REST API fields
dexter-sim Sep 22, 2024
d0bcc2c
Add front end button and modal for Trofos integration
dexter-sim Sep 22, 2024
ca614e5
Add course update API call logic for Trofos integration
dexter-sim Sep 22, 2024
7dc6d09
Change import ordering
dexter-sim Sep 22, 2024
cc88098
Add pagination to Octokit REST API calls
dexter-sim Sep 27, 2024
0b5825f
Create boilerplate code for Trofos cron job
dexter-sim Sep 30, 2024
6703a71
Create fetch jobs for Trofos course and projects
dexter-sim Sep 30, 2024
53aadcc
Add Trofos registration check in backend cron job
dexter-sim Sep 30, 2024
a303119
Create a function to fetch a single Trofos project
dexter-sim Oct 1, 2024
7ad5286
Merge pull request #200 from rjkoh/sonar
rjkoh Oct 2, 2024
91c7b91
Update Trofos API endpoints to Trofos production server
dexter-sim Oct 6, 2024
68cec52
Add fetch Trofos sprint function
dexter-sim Oct 6, 2024
9fe561e
Add fetch Trofos backlog function
dexter-sim Oct 6, 2024
3d40164
Merge pull request #221 from NUS-CRISP/bugfixes-2
dexter-sim Oct 6, 2024
db30d18
Merge branch 'staging' into add-trofos
dexter-sim Oct 6, 2024
3e77cf4
Fix formatting
dexter-sim Oct 6, 2024
bcbdb7b
Update project management visualizations
dexter-sim Oct 9, 2024
e902894
Merge pull request #202 from NUS-CRISP/add-trofos
dexter-sim Oct 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create boilerplate code for Trofos cron job
  • Loading branch information
dexter-sim committed Sep 30, 2024
commit 0b5825f8a4adb0b7b623a4c400f05a41b79b9f99
2 changes: 2 additions & 0 deletions backend/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { config } from 'dotenv';
import express, { Express } from 'express';
import setupGitHubJob from './jobs/githubJob';
import setupJiraJob from './jobs/jiraJob';
import setupTrofosJob from './jobs/trofosJob';
import accountRoutes from './routes/accountRoutes';
import assessmentRoutes from './routes/assessmentRoutes';
import courseRoutes from './routes/courseRoutes';
Expand All @@ -21,6 +22,7 @@ const setupApp = async () => {
await connectToDatabase();
setupGitHubJob();
setupJiraJob();
setupTrofosJob();
};
setupApp();

Expand Down
37 changes: 37 additions & 0 deletions backend/jobs/trofosJob.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import cron from 'node-cron';
import { URLSearchParams } from 'url';
import { Course } from '@models/Course';
import CourseModel from '@models/Course';

const fetchAndSaveTrofosData = async () => {
const trofosCourseUri = 'https://trofos.comp.nus.edu.sg/api/external/v1/course';
const trofosProjectUri = 'https://trofos.comp.nus.edu.sg/api/external/v1/project';

const courses: Course[] = await CourseModel.find();

for (const course of courses) {
const apiKey = course.trofos.apiKey;

}
}

const setupTrofosJob = () => {
// Schedule the job to run every day at 01:00 hours
cron.schedule('0 3 * * *', async () => {
console.log('Running fetchAndSaveTrofosData job:', new Date().toString());
try {
await fetchAndSaveTrofosData();
} catch (err) {
console.error('Error in cron job fetchAndSaveTrofosData:', err);
}
});

// To run the job immediately for testing
if (process.env.RUN_JOB_NOW === 'true') {
fetchAndSaveTrofosData().catch(err => {
console.error('Error running job manually:', err);
});
}
};

export default setupTrofosJob;
40 changes: 40 additions & 0 deletions trofos-project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"id": 10,
"pname": "crisp-project-1",
"pkey": "c1",
"description": null,
"course_id": 18,
"public": false,
"created_at": "2024-09-15T12:54:06.748Z",
"backlog_counter": 1,
"telegramChannelLink": null,
"is_archive": null,
"course": {
"id": 18,
"code": "crisp",
"startYear": 2024,
"startSem": 1,
"endYear": 2024,
"endSem": 1,
"cname": "crisp course",
"description": null,
"public": false,
"created_at": "2024-09-15T12:53:21.666Z",
"shadow_course": false,
"milestones": []
},
"users": [
{
"user": {
"user_id": 21,
"user_email": "[email protected]",
"user_display_name": "crisp_faculty",
"courses": [
{ "id": 40, "user_id": 21, "role_id": 1, "course_id": 18 }
]
}
}
]
}
]