Skip to content

Commit

Permalink
Merge pull request #52 from cicirello/dev
Browse files Browse the repository at this point in the history
Added featured repo, animated language chart option, other improvements
  • Loading branch information
cicirello authored Aug 6, 2021
2 parents 8549538 + fc8bdc1 commit fa2273a
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 44 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
with:
colors: dark
commit-and-push: false
featured-repository: Chips-n-Salsa
animated-language-chart: true
#fail-on-error: false
#category-order: general, repositories, languages, contributions
env:
Expand Down
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] - 2021-08-04
## [Unreleased] - 2021-08-06

### Added

Expand All @@ -17,6 +17,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed


## [1.5.0] - 2021-08-06

### Added
* A new action input, `featured-repository`, that enables the user of the action
to (optionally) specify a repository to feature in the General Stats and Info
section of the SVG. For example, perhaps they have a repository that they feel
is a better representative of their work than their most starred and most forked
repositories.
* An option to animate the language distribution chart, a continuous rotation of the
pie chart. This feature is disabled by default. It is controlled by a pair of new inputs:
`animated-language-chart` and `language-animation-speed`.

### Fixed
* Corrected bug in edge case when user only owns forks, which had been causing the
action to fail with an exception.


## [1.4.0] - 2021-08-04

### Added
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ following.
| Key | Statistic | Details |
| --- | --- | ------ |
| `joined` | Year Joined | the year user joined GitHub |
| `featured` | Featured repository | user optionally selects this with an input |
| `mostStarred` | Most starred repository | name of repo |
| `mostForked` | Most forked repository | name of repo |
| `followers` | Followers | simple count |
Expand Down Expand Up @@ -582,6 +583,17 @@ length of a custom title, or if you use the default title but have a long name,
title may overflow the viewbox of the SVG. In a case like this, you can pass
`small-title: true`, which will decrease the font size of the title to 16px.

### `featured-repository`

If you want to feature a repository in the General Stats and Info section,
you can use this input to do so. For example, although the action includes
the Most Starred and Most Forked repositories in that section by default,
perhaps there is another repository that you are particularly proud of, or
which you feel is a better representative of your overall work. The default is
nothing featured since it is impossible to predict what you would want here.
To use, just pass the name of the repository via this input. Note that the action
doesn't attempt to validate whether this repository actually exists.

### `max-languages`

This input is the maximum number of languages to explicitly include in
Expand Down Expand Up @@ -629,6 +641,21 @@ YAML's ways to specify a multiline string):
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
```

### `animated-language-chart`

This input can be used to enable animation of the languages pie chart.
This feature is disabled by default. You can enable it with: `animated-language-chart: true`.
If enabled, the pie chart will rotate continuously.

### `language-animation-speed`

If you enable the language chart animation using the `animated-language-chart` input,
then you can control the speed of the animation with the `language-animation-speed`
input. The default is a full rotation in 10 seconds. Perhaps you want
a slower rotation, such as 20 seconds, then you can pass: `language-animation-speed: 20`.
Or perhaps you want a faster rotation, such as 5 seconds,
then you can pass: `language-animation-speed: 5`. The input must be an integer.

### `colors`

The `colors` input enables you to either select from a set of
Expand Down Expand Up @@ -808,8 +835,11 @@ jobs:
include-title: true
custom-title: '' # Defaults to title pattern described earlier
small-title: false
featured-repository: '' # Defaults to nothing featured
max-languages: auto
language-repository-exclusions: '' # None excluded
animated-language-chart: false
language-animation-speed: 10
colors: light
border-radius: 6
show-border: true
Expand Down
15 changes: 15 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ inputs:
description: 'List of repositories to exclude from language stats.'
required: false
default: ''
featured-repository:
description: 'Name of a repository to feature in the General Stats and Info section'
required: false
default: ''
animated-language-chart:
description: 'Boolean controlling whether the language chart is animated'
required: false
default: false
language-animation-speed:
description: 'The time for one full rotation in seconds'
required: false
default: 10
outputs:
exit-code:
description: '0 if successful or non-zero if unsuccessful'
Expand All @@ -106,3 +118,6 @@ runs:
- ${{ inputs.max-languages }}
- ${{ inputs.category-order }}
- ${{ inputs.language-repository-exclusions }}
- ${{ inputs.featured-repository }}
- ${{ inputs.animated-language-chart }}
- ${{ inputs.language-animation-speed }}
1 change: 1 addition & 0 deletions octicons/ruby-16.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion src/PieChart.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
_headerTemplate = '<svg viewBox="0 0 {0} {0}" width="{0}" height="{0}">'
_pathTemplate = '<path fill-rule="evenodd" fill="{0}" d="M {1},{2} A {3} {3} 0 {4} {5} {6} {7} L {3},{3} Z"/>'
_circleTemplate = '<circle fill="{0}" cx="{1}" cy="{1}" r="{1}"/>'
_animationTemplate = '<animateTransform attributeName="transform" attributeType="XML" type="rotate" from="0 {0} {0}" to="360 {0} {0}" dur="{1}s" repeatCount="indefinite"/>'

def svgPieChart(wedges, radius) :
def svgPieChart(wedges, radius, animate, speed) :
"""Generates an SVG of a pie chart. The intention is to include
as part of a larger SVG (e.g., it does not insert xmlns into the
opening svg tag). If wedges list is empty, it retrurns None.
Expand All @@ -40,6 +41,8 @@ def svgPieChart(wedges, radius) :
wedges - A list of Python dictionaries, with each dictionary
containing fields color and percentage.
radius - the radius, in pixels for the pie chart.
animate - Pass True to animate the pie chart.
speed - If animate is True, then this input is the number of seconds for one full rotation.
"""
components = [_headerTemplate.format(str(2*radius))]

Expand All @@ -59,6 +62,9 @@ def svgPieChart(wedges, radius) :
# (i.e., last edge should complete a full circle).
wedges[-1]["end"] = 2 * math.pi

if animate :
components.append("<g>")

for w in wedges :
components.append(
_pathTemplate.format(
Expand All @@ -72,6 +78,15 @@ def svgPieChart(wedges, radius) :
radius + radius * math.sin(w["end"]+math.pi)
)
)

if animate :
components.append(
_animationTemplate.format(
radius,
speed
)
)
components.append("</g>")

components.append("</svg>")
return "".join(components)
8 changes: 8 additions & 0 deletions src/StatConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
statsByCategory = {
"general" : [
"joined",
"featured",
"mostStarred",
"mostForked",
"followers",
Expand Down Expand Up @@ -154,6 +155,13 @@
}
},

"featured" : {
"icon" : '<path fill-rule="evenodd" d="M3.637 2.291A.75.75 0 014.23 2h7.54a.75.75 0 01.593.291l3.48 4.5a.75.75 0 01-.072.999l-7.25 7a.75.75 0 01-1.042 0l-7.25-7a.75.75 0 01-.072-.999l3.48-4.5zM4.598 3.5L1.754 7.177 8 13.207l6.246-6.03L11.402 3.5H4.598z"/>',
"label" : {
"en" : "Featured Repo"
}
},

"mostStarred" : {
"icon" : '<path fill-rule="evenodd" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.75.75 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25zm0 2.445L6.615 5.5a.75.75 0 01-.564.41l-3.097.45 2.24 2.184a.75.75 0 01.216.664l-.528 3.084 2.769-1.456a.75.75 0 01.698 0l2.77 1.456-.53-3.084a.75.75 0 01.216-.664l2.24-2.183-3.096-.45a.75.75 0 01-.564-.41L8 2.694v.001z"/>',
"label" : {
Expand Down
25 changes: 19 additions & 6 deletions src/Statistician.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class Statistician :
'_languages',
'_autoLanguages',
'_maxLanguages',
'_languageRepoExclusions'
'_languageRepoExclusions',
'_featuredRepo'
]

def __init__(self, fail, autoLanguages, maxLanguages, languageRepoExclusions) :
def __init__(self, fail, autoLanguages, maxLanguages, languageRepoExclusions, featuredRepo) :
"""The initializer executes the queries and parses the results.
Upon completion of the intitializer, the user statistics will
be available.
Expand All @@ -62,6 +63,7 @@ def __init__(self, fail, autoLanguages, maxLanguages, languageRepoExclusions) :
self._autoLanguages = autoLanguages
self._maxLanguages = maxLanguages if maxLanguages >= 1 else 1
self._languageRepoExclusions = languageRepoExclusions
self._featuredRepo = featuredRepo
self.ghDisableInteractivePrompts()
basicStatsQuery = self.loadQuery("/queries/basicstats.graphql",
fail)
Expand Down Expand Up @@ -169,6 +171,10 @@ def parseStats(self, basicStats, repoStats, watchingStats, reposContributedToSta
self._user["sponsors"] = [ basicStats["data"]["user"]["sponsorshipsAsMaintainer"]["totalCount"] ]
self._user["sponsoring"] = [ basicStats["data"]["user"]["sponsorshipsAsSponsor"]["totalCount"] ]

#
if self._featuredRepo != None :
self._user["featured"] = [ self._featuredRepo ]

# Extract all time counts of issues and pull requests
issues = basicStats["data"]["user"]["issues"]["totalCount"]
pullRequests = basicStats["data"]["user"]["pullRequests"]["totalCount"]
Expand Down Expand Up @@ -206,10 +212,17 @@ def parseStats(self, basicStats, repoStats, watchingStats, reposContributedToSta
forksOfMyReposAll = sum(repo["forkCount"] for page in repoStats if page["nodes"] != None for repo in page["nodes"] if not repo["isPrivate"])

# Find repos with most stars and most forks
mostStars = max( (repo for page in repoStats if page["nodes"] != None for repo in page["nodes"] if not repo["isPrivate"] and not repo["isFork"]), key=lambda x : x["stargazerCount"])["name"]
mostForks = max( (repo for page in repoStats if page["nodes"] != None for repo in page["nodes"] if not repo["isPrivate"] and not repo["isFork"]), key=lambda x : x["forkCount"])["name"]
self._user["mostStarred"] = [ mostStars ]
self._user["mostForked"] = [ mostForks ]
try :
mostStars = max( (repo for page in repoStats if page["nodes"] != None for repo in page["nodes"] if not repo["isPrivate"] and not repo["isFork"]), key=lambda x : x["stargazerCount"])["name"]
self._user["mostStarred"] = [ mostStars ]
except ValueError:
pass

try :
mostForks = max( (repo for page in repoStats if page["nodes"] != None for repo in page["nodes"] if not repo["isPrivate"] and not repo["isFork"]), key=lambda x : x["forkCount"])["name"]
self._user["mostForked"] = [ mostForks ]
except ValueError:
pass

# Compute number of watchers excluding cases where user is watching their own repos.
watchers = sum(repo["watchers"]["totalCount"] for page in repoStats if page["nodes"] != None for repo in page["nodes"] if not repo["isPrivate"])
Expand Down
Loading

0 comments on commit fa2273a

Please sign in to comment.