This Ballerina program counts GitHub repositories by language using the GitHub GraphQL API.
- Count repositories by programming language
- Filter by creation date
- Support for both local execution and GitHub Actions
- Uses GitHub GraphQL API for efficient data retrieval
- Download and install Ballerina (version 2201.8.0 or later)
- GitHub personal access token with appropriate permissions
The application uses environment variables for configuration:
packagePAT: Your GitHub personal access tokenlanguage: The programming language to search for (e.g., "ballerina", "python", "javascript")createdBefore: Date filter in formatYYYY-MM-DD(optional, defaults to current date)
Create a Config.toml file in the root directory of the project with the following configuration:
token = "<GitHub Personal Access Token>"
language = "<programming language>"
createdBefore = "<YYYY-MM-DD>" # Optional, defaults to current date- Fork this repository
- Add your GitHub personal access token as a repository secret:
- Go to your repository settings
- Navigate to "Secrets and variables" → "Actions"
- Add a new secret named
packagePATwith your GitHub token
- Go to the "Actions" tab in your repository
- Select "Count the Number of Repos" workflow
- Click "Run workflow"
- Enter the language you want to search for (defaults to "ballerina")
- Optionally enter a date in
YYYY-MM-DDformat to filter repositories created before that date - Click "Run workflow"
-
Clone this repository:
git clone <repository-url> cd github-stats
-
Create a
Config.tomlfile in the root directory:token = "your-github-personal-access-token" language = "ballerina" createdBefore = "2024-01-01" # Optional
-
Run the program:
bal run
The program will output the count of repositories in the following format:
No. of repos: <count>
- Count all Ballerina repositories: Set
language=ballerina - Count Python repositories created before 2023: Set
language=pythonandcreatedBefore=2023-01-01 - Count JavaScript repositories: Set
language=javascript
- Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
- Click "Generate new token (classic)"
- Give it a descriptive name
- Select the following scopes:
public_repo(for public repositories)repo(for private repositories, if needed)
- Click "Generate token"
- Copy the token and use it as the
tokenvalue in yourConfig.tomlfile
- Ballerina GraphQL client for API communication
- Ballerina IO for console output
- Ballerina OS for environment variable access