-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remote data: Add activities section for matrix, mail and github
- Loading branch information
Lino
committed
Feb 13, 2024
1 parent
38a53a4
commit 1b7c61a
Showing
11 changed files
with
216 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
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
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
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
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
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,34 @@ | ||
{{/* Number of repos in the organization. | ||
Private and archived repos are included. */}} | ||
{{ $repo_list_json := getJSON "https://api.github.com/orgs/freifunk-berlin/repos?per_page=100&sort=pushed"}} | ||
{{ $repo_count := len $repo_list_json}} | ||
|
||
{{/* Top three active repos. | ||
Based on latest push. */}} | ||
{{ $top_repos := slice }} | ||
{{ range $index, $element := $repo_list_json }} | ||
{{ if eq $index 3 }} | ||
{{ break }} | ||
{{ end }} | ||
{{ $top_repos = $top_repos | append $element.name }} | ||
{{ end }} | ||
|
||
{{/* Number of commits of the last seven days in the most active repos. | ||
Checking all repos would take to long. This only represents a a part of the total commits. A plus gets always appended to the counter. */}} | ||
{{ $past_seven_days_date := now.AddDate 0 0 -7 }} | ||
{{ $past_seven_days := $past_seven_days_date.Format "2006-01-02T15:04:05Z" }} | ||
{{ $commit_count := 0 }} | ||
|
||
{{ range $element := $top_repos }} | ||
{{ $commit_url := printf "https://api.github.com/repos/freifunk-berlin/%s/commits?per_page=100&since=%s" $element $past_seven_days }} | ||
{{ $commit_json := getJSON $commit_url }} | ||
{{ $commit_count = add $commit_count (len $commit_json) }} | ||
{{ end }} | ||
{{ $commit_count = printf "%d+" $commit_count }} | ||
|
||
{{/* Return map with the github activity data: | ||
- repo_count | ||
- top_repos | ||
- commit_count */}} | ||
{{ $github_activity := dict "repo_count" $repo_count "top_repos" $top_repos "commit_count" $commit_count }} | ||
{{ return $github_activity}} |
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,50 @@ | ||
{{/* Return the five latest subjects from the mailing list. | ||
Only checks the current and previous month. Duplicates are removed, when they follow each other directly. */}} | ||
{{ $current_month := now.Format "2006-January" }} | ||
{{ $current_month_url := printf "https://lists.berlin.freifunk.net/pipermail/berlin/%s/subject.html" $current_month }} | ||
{{ $current_month_response := resources.GetRemote $current_month_url }} | ||
{{ $current_month_html := $current_month_response.Content }} | ||
{{ $current_month_subjects := findRE "\\[Berlin-wireless\\] (.*?)\n" $current_month_html }} | ||
{{ $current_month_reversed_subjects := slice }} | ||
{{ $array_length := len $current_month_subjects }} | ||
{{- range $index, $element := $current_month_subjects -}} | ||
{{ $current_month_reversed_subjects = $current_month_reversed_subjects | append (index $current_month_subjects (sub $array_length (add $index 1))) }} | ||
{{- end }} | ||
|
||
{{ $previous_month_date := now.AddDate 0 -1 0 }} | ||
{{ $previous_month := $previous_month_date.Format "2006-January" }} | ||
{{ $previous_month_url := printf "https://lists.berlin.freifunk.net/pipermail/berlin/%s/subject.html" $previous_month }} | ||
{{ $previous_month_response := resources.GetRemote $previous_month_url }} | ||
{{ $previous_month_html := $previous_month_response.Content }} | ||
{{ $previous_month_subjects := findRE "\\[Berlin-wireless\\] (.*?)\n" $previous_month_html }} | ||
{{ $previous_month_reversed_subjects := slice }} | ||
{{ $array_length := len $previous_month_subjects }} | ||
{{- range $index, $element := $previous_month_subjects -}} | ||
{{ $previous_month_reversed_subjects = $previous_month_reversed_subjects | append (index $previous_month_subjects (sub $array_length (add $index 1))) }} | ||
{{- end }} | ||
|
||
{{ $subjects := $current_month_reversed_subjects | append $previous_month_reversed_subjects }} | ||
|
||
{{ $previous_subject := "" }} | ||
{{ $current_subject := "" }} | ||
{{ $subject_count := 0 }} | ||
{{ $latest_subjects := slice }} | ||
|
||
{{ range $element := $subjects }} | ||
|
||
{{ if eq $subject_count 5 }} | ||
{{ break }} | ||
{{ end }} | ||
|
||
{{ $current_subject = trim (strings.TrimPrefix "[Berlin-wireless]" $element) " " }} | ||
|
||
{{ if not (eq $previous_subject $current_subject) }} | ||
{{ $subject_count = add $subject_count 1 }} | ||
{{ $latest_subjects = $latest_subjects | append $current_subject }} | ||
{{ end }} | ||
|
||
{{ $previous_subject = $current_subject }} | ||
|
||
{{ end }} | ||
|
||
{{ return $latest_subjects }} |
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,59 @@ | ||
{{ $ACCESS_TOKEN := getenv "HUGO_MATRIX_ACCESS_TOKEN" }} | ||
{{ $HOME_SERVER := getenv "HUGO_MATRIX_HOME_SERVER" }} | ||
|
||
{{/* Number of members in main chat. */}} | ||
{{ $room_url := printf "%s/_matrix/client/v1/rooms/!zTqqomsFqlyQjqrZpm:matrix.org/hierarchy?access_token=%s" $HOME_SERVER $ACCESS_TOKEN }} | ||
{{ $room_json := getJSON $room_url }} | ||
{{ $room := index $room_json.rooms 0 }} | ||
|
||
|
||
{{/* Number of rooms in the space. | ||
Only checks the first page. If more rooms exist, a plus gets appended to the counter. | ||
Max rooms per page depends on server configuration. */}} | ||
{{ $space_url := printf "%s/_matrix/client/v1/rooms/!EzZtBKEuKZqxrYSugs:digitale-gesellschaft.ch/hierarchy?access_token=%s" $HOME_SERVER $ACCESS_TOKEN }} | ||
{{ $space_json := getJSON $space_url }} | ||
{{ $room_count := len $space_json.rooms }} | ||
{{ if isset $space_json "next_batch" }} | ||
{{ $room_count = printf "%d+" $room_count}} | ||
{{ end }} | ||
|
||
|
||
{{/* Number of messages in the past seven days in main chat. | ||
Only checks the first page. If the oldest message on that page is within the seven days, a plus gets appended to the counter. | ||
Max messages per page depends on server configuration. */}} | ||
{{ $messages_url := printf "%s/_matrix/client/v3/rooms/!zTqqomsFqlyQjqrZpm:matrix.org/messages?access_token=%s&limit=100&dir=b" $HOME_SERVER $ACCESS_TOKEN }} | ||
{{ $messages_json := getJSON $messages_url }} | ||
|
||
{{ $oneWeekAgoUnixSeconds := now.Unix | sub 604800 }} | ||
{{ $oneWeekAgoUnixMilliseconds := $oneWeekAgoUnixSeconds | mul -1000 }} | ||
|
||
{{ $message_array_len := len $messages_json.chunk }} | ||
{{ $message_last_index := sub $message_array_len 1 }} | ||
|
||
{{ $message_count := 0 }} | ||
{{ $oneWeekAgoUnixMilliseconds}} | ||
|
||
{{ range $index, $element := $messages_json.chunk }} | ||
|
||
{{ if gt $element.origin_server_ts $oneWeekAgoUnixMilliseconds }} | ||
{{$element.origin_server_ts}} | ||
|
||
{{ $message_count = add $message_count 1 }} | ||
|
||
{{ if eq $index $message_last_index }} | ||
{{ $message_count = printf "%d+" $message_count}} | ||
{{ end }} | ||
|
||
{{ else }} | ||
{{ break }} | ||
{{ end }} | ||
|
||
{{ end }} | ||
|
||
|
||
{{/* Return map with the matrix activity data: | ||
- message_count | ||
- room_count | ||
- member_count */}} | ||
{{ $matrix_activity := dict "message_count" $message_count "room_count" $room_count "member_count" $room.num_joined_members }} | ||
{{ return $matrix_activity}} |
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,19 @@ | ||
{{ $github_activity := partial "github-activity.html" . }} | ||
|
||
{{ if eq .Site.Language.Lang "de" }} | ||
Zur Versionsverwaltunng der Software nutzen wir <a href="https://github.com/freifunk-berlin/">Github</a>. | ||
Dort gab es in den letzten sieben Tagen <b>{{ $github_activity.commit_count }} (commits)</b> Änderungen am Code. | ||
Auf der Platform werden insgesamt <b>{{ $github_activity.repo_count }} (repositories)</b> Projekte verwaltet. | ||
Die aktivsten sind derzeit: | ||
{{ else if eq .Site.Language.Lang "en" }} | ||
We use <a href="https://github.com/freifunk-berlin/">Github</a> for version control of the software. | ||
There have been <b>{{ $github_activity.commit_count }} (commits)</b> changes to the code in the last seven days. | ||
A total of <b>{{ $github_activity.repo_count }} (repositories)</b> projects are managed on the platform. | ||
The most active are currently: | ||
{{ end }} | ||
|
||
<ul style="text-align:left;margin-left: auto;margin-right: auto;width: fit-content;"> | ||
{{ range $element := $github_activity.top_repos }} | ||
<li><a href="https://github.com/freifunk-berlin/{{ $element }}">{{ $element }}</a></li> | ||
{{ end }} | ||
</ul> |
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,13 @@ | ||
{{ $mail_subjects := partial "mail-subjects.html" . }} | ||
|
||
{{ if eq .Site.Language.Lang "de" }} | ||
Auf der <a href="https://lists.berlin.freifunk.net/cgi-bin/mailman/listinfo/berlin">Mailingliste</a> werden gerade folgende Themen diskutiert: | ||
{{ else if eq .Site.Language.Lang "en" }} | ||
The following topics are currently being discussed on the <a href="https://lists.berlin.freifunk.net/cgi-bin/mailman/listinfo/berlin">mailing list</a>: | ||
{{ end }} | ||
|
||
<ul style="text-align:left;margin-left: auto;margin-right: auto;width: fit-content;"> | ||
{{ range $element := $mail_subjects }} | ||
<li>{{ $element }}</li> | ||
{{ end }} | ||
</ul> |
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,11 @@ | ||
{{ $matrix_activity := partial "matrix-activity.html" . }} | ||
|
||
{{ if eq .Site.Language.Lang "de" }} | ||
Im <a href="https://matrix.to/#/#berlin.freifunk.net:matrix.org">Freifunk Berlin Matrix Space</a> gibt es aktuell | ||
<b>{{ $matrix_activity.room_count }} Chat-Räume mit {{ $matrix_activity.member_count }} Usern</b>. | ||
Im Hauptchat wurden in den letzten sieben Tagen <b>{{ $matrix_activity.message_count }} Nachrichten</b> verschickt. | ||
{{ else if eq .Site.Language.Lang "en" }} | ||
In the <a href="https://matrix.to/#/#berlin.freifunk.net:matrix.org">Freifunk Berlin Matrix Space</a> there are currently | ||
<b>{{ $matrix_activity.room_count }} chat rooms with {{ $matrix_activity.member_count }} users</b>. | ||
In the main chat <b>{{ $matrix_activity.message_count }} messages</b> have been sent in the last seven days. | ||
{{ end }} |