Skip to content

Commit ee2c342

Browse files
Merge pull request #296 from mergestat/audit-log-additional-cols
feat: add `actor_location` column to the `github_org_audit_log` table
2 parents 58f2c6d + b08d715 commit ee2c342

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

extensions/internal/github/org_audit_log.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package github
22

33
import (
44
"context"
5+
"encoding/json"
56
"io"
67
"strings"
78
"time"
@@ -33,6 +34,13 @@ type auditLogEntryContents struct {
3334
}
3435
ActorLogin string
3536
ActorIp string
37+
ActorLocation struct {
38+
City string `json:"city"`
39+
Country string `json:"country"`
40+
CountryCode string `json:"countryCode"`
41+
Region string `json:"region"`
42+
RegionCode string `json:"regionCode"`
43+
}
3644
CreatedAt githubv4.DateTime
3745
OperationType string
3846
UserLogin string
@@ -107,6 +115,12 @@ func (i *iterOrgAuditLogs) Column(ctx vtab.Context, c int) error {
107115
ctx.ResultText(current.Entry.ActorLogin)
108116
case "actor_ip":
109117
ctx.ResultText(current.Entry.ActorIp)
118+
case "actor_location":
119+
if s, err := json.Marshal(current.Entry.ActorLocation); err != nil {
120+
return err
121+
} else {
122+
ctx.ResultText(string(s))
123+
}
110124
case "created_at":
111125
t := current.Entry.CreatedAt
112126
if t.IsZero() {
@@ -163,6 +177,7 @@ var orgAuditCols = []vtab.Column{
163177
{Name: "actor_type", Type: "TEXT"},
164178
{Name: "actor_login", Type: "TEXT"},
165179
{Name: "actor_ip", Type: "TEXT"},
180+
{Name: "actor_location", Type: "JSON"},
166181
{Name: "created_at", Type: "DATETIME", OrderBy: vtab.ASC | vtab.DESC},
167182
{Name: "operation_type", Type: "TEXT"},
168183
{Name: "user_login", Type: "TEXT"},

extensions/internal/github/org_audit_log_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestOrgAuditLog(t *testing.T) {
2323
t.Fatalf("failed to retrieve row contents: %v", err.Error())
2424
}
2525

26-
if expected := 9; colCount != expected {
26+
if expected := 10; colCount != expected {
2727
t.Fatalf("expected %d columns, got: %d", expected, colCount)
2828
}
2929
}

0 commit comments

Comments
 (0)