Skip to content

Commit 757c5d8

Browse files
committed
Hopefully working?
1 parent a146c04 commit 757c5d8

3 files changed

Lines changed: 70 additions & 9 deletions

File tree

dist/index.js

Lines changed: 33 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@ import * as core from '@actions/core'
22
import { exec } from '@actions/exec'
33
import { execSync } from 'child_process'
44
import sqlite3 from 'sqlite3'
5-
import { open } from 'sqlite'
5+
import { Database, open } from 'sqlite'
66

7+
const dbfile = 'github-archive.db'
8+
const events = [
9+
'issues',
10+
'issue_comment',
11+
'pull_request',
12+
'pull_request_review',
13+
'pull_request_review_comment',
14+
]
715
async function run(): Promise<void> {
816
core.info(
917
'[INFO] Usage https://github.com/githubocto/github-archive-action#readme'
1018
)
11-
core.startGroup('Setup')
1219

20+
core.startGroup('Setup')
1321
// Configure git user/email
1422
const username = 'github-archive-action'
1523
await exec('git', ['config', 'user.name', username])
@@ -39,19 +47,42 @@ async function run(): Promise<void> {
3947

4048
// open the database
4149
const db = await open({
42-
filename: 'github-archive.db',
50+
filename: dbfile,
4351
driver: sqlite3.Database,
4452
})
4553

54+
// create tables if they don't exist
4655
await db.run(`
47-
CREATE TABLE IF NOT EXISTS issues (
56+
CREATE TABLE IF NOT EXISTS events (
4857
id INTEGER PRIMARY KEY,
49-
timestamp TEXT NOT NULL,
58+
timestamp TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
59+
kind TEXT NOT NULL
5060
event TEXT NOT NULL
5161
);`)
5262
core.endGroup()
5363

64+
core.startGroup('Capture event')
65+
for await (const e of events) {
66+
core.debug(`Checking for "${e}" event...`)
67+
const payload = core.getInput(e)
68+
if (payload === '') {
69+
// no event
70+
return
71+
}
72+
await db.run('INSERT INTO events (kind, event) values (:e, :payload)', {
73+
e,
74+
payload,
75+
})
76+
core.info(`Captured ${e} event`)
77+
}
78+
core.endGroup()
79+
80+
core.startGroup('Commit and close db')
5481
await db.close()
82+
await exec('git', ['add', dbfile])
83+
await exec('git', ['commit', '-m', 'Adding data to repo'])
84+
await exec('git', ['push'])
85+
core.endGroup()
5586
}
5687

5788
run().catch(error => {

0 commit comments

Comments
 (0)