-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d72c05d
commit cc10868
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Aggregate applicant data | ||
|
||
on: | ||
push: | ||
paths: | ||
- "data/**" | ||
|
||
# allow for manual deploys | ||
workflow_dispatch: | ||
|
||
jobs: | ||
aggregate: | ||
runs-on: ubuntu-latest | ||
if: vars.PROCESSOR_ENABLED == 'true' && contains(github.event.issue.labels.*.name, 'application') | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Fetch processor | ||
uses: dsaltares/fetch-gh-release-asset@1.1.1 | ||
with: | ||
file: "processor" | ||
target: "./processor" | ||
|
||
- name: Aggregate applicant data | ||
run: | | ||
chmod +x ./processor | ||
./processor aggregate | ||
env: | ||
SENTRY_DSN: ${{ secrets.SENTRY_DSN }} | ||
OP_BOT_PAT: ${{ secrets.OP_BOT_PAT }} | ||
REPOSITORY_OWNER: ${{ github.repository_owner }} | ||
REPOSITORY_NAME: ${{ github.event.repository.name }} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
"github.com/getsentry/sentry-go" | ||
) | ||
|
||
type ProjectEntry struct { | ||
Project Project `json:"project"` | ||
CreatedAt time.Time `json:"created_at"` | ||
} | ||
|
||
type Aggregator struct { | ||
gitHub *GitHub | ||
} | ||
|
||
func (a *Aggregator) Aggregate() { | ||
if err := a.gitHub.Init(); err != nil { | ||
a.logErrorAndExit("could not initialize GitHub client", err) | ||
} | ||
|
||
dataDir := "./data" | ||
var projectsList []ProjectEntry | ||
|
||
if err := filepath.Walk(dataDir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// There may in the future be a non-JSON file living in | ||
// this directory, so let's safeguard against that | ||
if !info.IsDir() && filepath.Ext(path) == ".json" { | ||
file, err := os.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var app Application | ||
err = json.Unmarshal(file, &app) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
projectEntry := ProjectEntry{ | ||
Project: app.Project, | ||
CreatedAt: app.CreatedAt, | ||
} | ||
|
||
projectsList = append(projectsList, projectEntry) | ||
} | ||
|
||
return nil | ||
}); err != nil { | ||
a.logErrorAndExit("failed to aggregate applicant data", err) | ||
} | ||
|
||
aggregateData, err := json.Marshal(projectsList) | ||
if err != nil { | ||
a.logErrorAndExit("failed to marshal projects into JSON", err) | ||
} | ||
|
||
outputFile := "./data.json" | ||
|
||
if err := a.gitHub.UpdateFile( | ||
outputFile, | ||
aggregateData, | ||
"Update applicant data", | ||
); err != nil { | ||
a.logErrorAndExit( | ||
"could not create commit", | ||
err, | ||
) | ||
} | ||
} | ||
|
||
func (a *Aggregator) logErrorAndExit(message string, err error) { | ||
sentry.CaptureException(err) | ||
log.Fatalf("Error aggregating data: %s: %s\n", message, err.Error()) | ||
} |
This file contains 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