GitHub Follower Management
GitHub Actions provide a powerful way to automate tasks within your repositories. One such task is managing followers, which can be streamlined using custom actions. Let's explore follower-sync, a GitHub Action I created to automate follower management on GitHub.
Understanding the Action
The follower-sync
action is designed to handle two main operations
- following users who are following you but you're not following back.
- unfollow users whom you're following but aren't follow you back.
Let's break down the key components of this action.
Dependencies
The action utilizes several dependencies:
@actions/core
For interacting with GitHub Actions core library.@octokit/rest
Enables interaction with the GitHub API.
Configuration Inputs
The action accepts the following inputs:
personal-access-token
GitHub personal access token for authentication.each-operation-delay
Optional delay between each operation.should-unfollow
Boolean flag to enable/disable unfollow user.should-follow
Boolean flag to enable/disable follow user.safe-list
List of users to exclude from unfollow.
Query Users
These functions retrieve the list of followers and followings of the current user from the GitHub API. queryFollowers
function retrieves the followers, while queryFollowing
retrieves the followings.
Identifying Users to Follow and Unfollow
This line of code filters out users who need to be unfollowed. It compares the followings array with the followers array and ensures that the user's login is not in the safeList or not among the followers, preparing a list of users to unfollow.
This line of code filters out users who need to be followed by comparing the followers array with the followings array to find users not already being followed.
Follow and Unfollow method
- These functions handle the unfollowing and following operations respectively.
unfollowUsers
unfollows each user in the list, whilefollowUsers
follows each user.- It then waits for a specified delay using the wait function before moving on to the next user.
Following and Unfollowing Users
The following code segment manages the process of following and unfollowing users based on the provided configurations:
- Unfollowing Users
- It checks if there are users to unfollow and if unfollowing is enabled. It proceeds to unfollow the users and logs the number of unfollowed users.
- Following Users
- Similarly, it checks if there are users to follow and if following is enabled. It follows the users and logs the number of followed users.
Conclusion
The follower-sync
action simplifies the process of managing GitHub followers by automating the task based on configurable inputs. By leveraging the GitHub Actions ecosystem, you can easily integrate this functionality into your workflow, saving time and effort in follower management.