Skip to content

Commit

Permalink
chore: release
Browse files Browse the repository at this point in the history
  • Loading branch information
imskr committed Feb 24, 2024
1 parent b3fb37b commit ee545f4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
Binary file added .DS_Store
Binary file not shown.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
# contributions-badge
Showcase your number of merged pull requests in profile's README dynamically

This project has MERGED_PULL_REQUESTS_COUNT merged pull requests.
> A github action workflow for showcasing your number of merged pull requests in profile's README dynamically
<p align="center">
<a href="https://github.com/imskr/contributions-badge/releases"><img alt="GitHub release (latest by date including pre-releases)" src="https://img.shields.io/github/v/release/imskr/contributions-badge?include_prereleases&style=flat-square"></a>
<a href="https://github.com/imskr/contributions-badge/actions/workflows/build.yml"><img alt="Actions workflow" src="https://img.shields.io/github/workflow/status/imskr/contributions-badge/Build/main?style=flat-square"></a>
<a href="https://github.com/imskr/contributions-badge/issues"><img alt="Github Issues" src="https://img.shields.io/github/issues/imskr/contributions-badge?color=orange&style=flat-square"></a>
</p>
<hr noshade>

## Usage

1. Go to your repository
2. Add the following to your **README.md** file, you can use any title. Just make sure that you use `<!-- MERGED_PULL_REQUESTS_COUNT -->` in your readme. The workflow will replace this comment with the number of merged pull requests:

```markdown
<!-- MERGED_PULL_REQUESTS_COUNT -->
```

3. Create a folder `.github/workflows` inside root of the repository if it doesn't exists.
4. Create a new file `contributions.yml` inside `.github/workflows/` with the following contents:

![](./public/images/contributions-workflow.png)

5. Replace the above `organization`, `project` and `username` with your data.
6. Commit and wait for it to run automatically, or you can also trigger it manually to see the result instantly.

> Currently we are only supporting public projects on GitLab


## Support

<p>
<a href="https://buymeacoffee.com/imskr" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-red.png" alt="Buy Me A Coffee" width="150" ></a>
</p>
15 changes: 7 additions & 8 deletions contributions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ class Contributions
def run
organization = ENV['INPUT_ORGANIZATION']
project = ENV['INPUT_PROJECT']
username = ENV['INPUT_USERNAME']
username = ENV['INPUT_USERNAME']
readme_path = ENV['INPUT_README_PATH']
git_username = ENV['INPUT_COMMIT_USER']
git_email = ENV['INPUT_COMMIT_EMAIL']
commit_message = ENV['INPUT_COMMIT_MESSAGE'] || 'Update README.md'

gitlab_url = "https://gitlab.com/api/v4/projects/#{organization}%2F#{project}/merge_requests?scope=all&state=merged&author_username=#{username}&per_page=1000"

uri = URI(gitlab_url)
Expand All @@ -22,17 +27,11 @@ def run
merged_count = merged_merge_requests.count

# Update README.md with the count
# readme_path = File.join(__dir__, 'README.md')
readme_path = ENV['INPUT_README_PATH']
git_username = ENV['INPUT_COMMIT_USER']
git_email = ENV['INPUT_COMMIT_EMAIL']

readme_content = File.read(readme_path)
updated_readme_content = readme_content.gsub(/MERGED_PULL_REQUESTS_COUNT/, merged_count.to_s)
updated_readme_content = readme_content.gsub(/<!-- MERGED_PULL_REQUESTS_COUNT -->/, merged_count.to_s)
File.write(readme_path, updated_readme_content)

# git flow
commit_message = ENV['INPUT_COMMIT_MESSAGE'] || 'Update README.md'
`git config --global --add safe.directory /github/workspace`
`git config user.name #{git_username}`
`git config user.email #{git_email}`
Expand Down
Binary file added public/.DS_Store
Binary file not shown.
Binary file added public/images/contributions-workflow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ee545f4

Please sign in to comment.