Created
March 21, 2023 19:08
-
-
Save ericksoa/bda5607fa96ac22819c32f60a79b429a to your computer and use it in GitHub Desktop.
Gather calendar events and commit stats for use in your upcoming 1:1 meeting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { exec } from "child_process"; | |
| import { google } from "googleapis"; | |
| import { Credentials } from "google-auth-library"; | |
| import axios from "axios"; | |
| const OPENAI_API_KEY = "<your_openai_api_key>"; | |
| const GIT_REPO_PATH = "<your_git_repo_path>"; | |
| const GOOGLE_CREDENTIALS = <your_google_credentials> as Credentials; | |
| async function getCommitStats(email: string, fromDate: string, toDate: string): Promise<string> { | |
| return new Promise((resolve, reject) => { | |
| exec( | |
| `git log --author="${email}" --since="${fromDate}" --until="${toDate}" --shortstat`, | |
| { cwd: GIT_REPO_PATH }, | |
| (error, stdout, stderr) => { | |
| if (error) reject(stderr); | |
| else resolve(stdout); | |
| } | |
| ); | |
| }); | |
| } | |
| async function getCalendarEvents(email: string, fromDate: string, toDate: string): Promise<any> { | |
| const auth = new google.auth.JWT( | |
| GOOGLE_CREDENTIALS.client_email, | |
| undefined, | |
| GOOGLE_CREDENTIALS.private_key, | |
| ["https://www.googleapis.com/auth/calendar.readonly"] | |
| ); | |
| const calendar = google.calendar({ version: "v3", auth }); | |
| const response = await calendar.events.list({ | |
| calendarId: email, | |
| timeMin: fromDate, | |
| timeMax: toDate, | |
| singleEvents: true, | |
| orderBy: "startTime", | |
| }); | |
| return response.data.items; | |
| } | |
| async function generateSummary(data: any): Promise<string> { | |
| const response = await axios.post( | |
| "https://api.openai.com/v1/engines/davinci-codex/completions", | |
| { | |
| prompt: `Generate a summary for an engineer's work in a given week. The data is as follows: ${JSON.stringify( | |
| data | |
| )}`, | |
| max_tokens: 150, | |
| n: 1, | |
| stop: null, | |
| temperature: 0.7, | |
| }, | |
| { | |
| headers: { | |
| "Content-Type": "application/json", | |
| "Authorization": `Bearer ${OPENAI_API_KEY}`, | |
| }, | |
| } | |
| ); | |
| return response.data.choices[0].text; | |
| } | |
| async function main() { | |
| const engineerEmail = "<engineer_email>"; | |
| const fromDate = "2023-03-13T00:00:00Z"; | |
| const toDate = "2023-03-20T23:59:59Z"; | |
| const commitStats = await getCommitStats(engineerEmail, fromDate, toDate); | |
| const calendarEvents = await getCalendarEvents(engineerEmail, fromDate, toDate); | |
| const data = { | |
| commitStats, | |
| calendarEvents, | |
| }; | |
| const summary = await generateSummary(data); | |
| console.log("Generated Summary:\n", summary); | |
| } | |
| main().catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment