Change default location for activity.json
This commit is contained in:
parent
f5140502fd
commit
d29732c17e
1 changed files with 56 additions and 14 deletions
|
|
@ -91,12 +91,15 @@ func parseArgs(args []string) (string, error) {
|
||||||
fs.Usage = func() {
|
fs.Usage = func() {
|
||||||
fmt.Fprintln(fs.Output(), "Usage: go run . [--output <path>]")
|
fmt.Fprintln(fs.Output(), "Usage: go run . [--output <path>]")
|
||||||
fmt.Fprintln(fs.Output(), "\nOptions:")
|
fmt.Fprintln(fs.Output(), "\nOptions:")
|
||||||
fmt.Fprintln(fs.Output(), " -o, --output <path> Where to write activity.json (default: ../static/activity.json)")
|
fmt.Fprintln(
|
||||||
|
fs.Output(),
|
||||||
|
" -o, --output <path> Where to write activity.json (default: activity.json)",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
var output string
|
var output string
|
||||||
fs.StringVar(&output, "output", "../static/activity.json", "Where to write activity.json")
|
fs.StringVar(&output, "output", "activity.json", "Where to write activity.json")
|
||||||
fs.StringVar(&output, "o", "../static/activity.json", "Where to write activity.json")
|
fs.StringVar(&output, "o", "activity.json", "Where to write activity.json")
|
||||||
|
|
||||||
if err := fs.Parse(args); err != nil {
|
if err := fs.Parse(args); err != nil {
|
||||||
if errors.Is(err, flag.ErrHelp) {
|
if errors.Is(err, flag.ErrHelp) {
|
||||||
|
|
@ -198,11 +201,13 @@ func (a app) areGHVarsPresent() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a app) areFJVarsPresent() bool {
|
func (a app) areFJVarsPresent() bool {
|
||||||
return strings.TrimSpace(a.config.forgejoAPIKey) != "" && strings.TrimSpace(a.config.forgejoUser) != ""
|
return strings.TrimSpace(a.config.forgejoAPIKey) != "" &&
|
||||||
|
strings.TrimSpace(a.config.forgejoUser) != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a app) areGLVarsPresent() bool {
|
func (a app) areGLVarsPresent() bool {
|
||||||
return strings.TrimSpace(a.config.gitlabAPIKey) != "" && strings.TrimSpace(a.config.gitlabUser) != ""
|
return strings.TrimSpace(a.config.gitlabAPIKey) != "" &&
|
||||||
|
strings.TrimSpace(a.config.gitlabUser) != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatGitHubTime(t time.Time) string {
|
func formatGitHubTime(t time.Time) string {
|
||||||
|
|
@ -488,8 +493,21 @@ func (a app) getForgejoActivityMap() (activityMap, error) {
|
||||||
result := activityMap{}
|
result := activityMap{}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
url := fmt.Sprintf("%s/api/v1/users/%s/activities/feeds?limit=%d&page=%d&after=%s", strings.TrimRight(a.config.forgejoURL, "/"), a.config.forgejoUser, pageLimit, page, a.formattedOneYearAgo)
|
url := fmt.Sprintf(
|
||||||
body, err := a.doJSONRequest(http.MethodGet, url, nil, map[string]string{"Authorization": "Bearer " + a.config.forgejoAPIKey}, "Forgejo")
|
"%s/api/v1/users/%s/activities/feeds?limit=%d&page=%d&after=%s",
|
||||||
|
strings.TrimRight(a.config.forgejoURL, "/"),
|
||||||
|
a.config.forgejoUser,
|
||||||
|
pageLimit,
|
||||||
|
page,
|
||||||
|
a.formattedOneYearAgo,
|
||||||
|
)
|
||||||
|
body, err := a.doJSONRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
url,
|
||||||
|
nil,
|
||||||
|
map[string]string{"Authorization": "Bearer " + a.config.forgejoAPIKey},
|
||||||
|
"Forgejo",
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -517,10 +535,16 @@ func (a app) ghFetch(query string) ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return a.doJSONRequest(http.MethodPost, "https://api.github.com/graphql", payload, map[string]string{
|
return a.doJSONRequest(
|
||||||
"Content-Type": "application/json",
|
http.MethodPost,
|
||||||
"Authorization": "Bearer " + a.config.githubAPIKey,
|
"https://api.github.com/graphql",
|
||||||
}, "GitHub")
|
payload,
|
||||||
|
map[string]string{
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"Authorization": "Bearer " + a.config.githubAPIKey,
|
||||||
|
},
|
||||||
|
"GitHub",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a app) getGitHubActivityMap() (activityMap, error) {
|
func (a app) getGitHubActivityMap() (activityMap, error) {
|
||||||
|
|
@ -638,8 +662,21 @@ func (a app) getGitLabActivityMap() (activityMap, error) {
|
||||||
afterDate := a.oneYearAgo.UTC().Format("2006-01-02")
|
afterDate := a.oneYearAgo.UTC().Format("2006-01-02")
|
||||||
|
|
||||||
for {
|
for {
|
||||||
url := fmt.Sprintf("%s/api/v4/users/%s/events?action=pushed&after=%s&per_page=%d&page=%d", strings.TrimRight(a.config.gitlabURL, "/"), a.config.gitlabUser, afterDate, pageLimit, page)
|
url := fmt.Sprintf(
|
||||||
body, err := a.doJSONRequest(http.MethodGet, url, nil, map[string]string{"PRIVATE-TOKEN": a.config.gitlabAPIKey}, "GitLab")
|
"%s/api/v4/users/%s/events?action=pushed&after=%s&per_page=%d&page=%d",
|
||||||
|
strings.TrimRight(a.config.gitlabURL, "/"),
|
||||||
|
a.config.gitlabUser,
|
||||||
|
afterDate,
|
||||||
|
pageLimit,
|
||||||
|
page,
|
||||||
|
)
|
||||||
|
body, err := a.doJSONRequest(
|
||||||
|
http.MethodGet,
|
||||||
|
url,
|
||||||
|
nil,
|
||||||
|
map[string]string{"PRIVATE-TOKEN": a.config.gitlabAPIKey},
|
||||||
|
"GitLab",
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -712,7 +749,12 @@ func (a app) makeActivityMap() (activityMap, error) {
|
||||||
return deduplicateAcrossPlatforms(merged, results[2]), nil
|
return deduplicateAcrossPlatforms(merged, results[2]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a app) doJSONRequest(method, url string, body []byte, headers map[string]string, apiName string) ([]byte, error) {
|
func (a app) doJSONRequest(
|
||||||
|
method, url string,
|
||||||
|
body []byte,
|
||||||
|
headers map[string]string,
|
||||||
|
apiName string,
|
||||||
|
) ([]byte, error) {
|
||||||
var reader io.Reader
|
var reader io.Reader
|
||||||
if body != nil {
|
if body != nil {
|
||||||
reader = bytes.NewReader(body)
|
reader = bytes.NewReader(body)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue