├── settings.gradle.kts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── src ├── main │ ├── resources │ │ ├── static │ │ │ └── images │ │ │ │ └── background.jpg │ │ ├── application.properties │ │ └── templates │ │ │ └── main.html │ └── kotlin │ │ └── com │ │ └── githubunfollowertracker │ │ ├── GitHubUnfollowerTrackerApplication.kt │ │ ├── controller │ │ ├── ViewController.kt │ │ └── GitHubController.kt │ │ ├── config │ │ └── AppConfig.kt │ │ ├── service │ │ ├── GetAccessTokenService.kt │ │ ├── FollowMonitoringService.kt │ │ └── GitHubService.kt │ │ └── dto │ │ └── GitHubUser.kt └── test │ └── kotlin │ └── com │ └── githubunfollowertracker │ └── GitHubUnfollowerTrackerApplicationTests.kt ├── .gitignore ├── gradlew.bat ├── README.md └── gradlew /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "GitHubUnfollowerTracker" 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krkarma777/GitHubUnfollowerTracker/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /src/main/resources/static/images/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/krkarma777/GitHubUnfollowerTracker/HEAD/src/main/resources/static/images/background.jpg -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /src/test/kotlin/com/githubunfollowertracker/GitHubUnfollowerTrackerApplicationTests.kt: -------------------------------------------------------------------------------- 1 | package com.githubunfollowertracker 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.springframework.boot.test.context.SpringBootTest 5 | 6 | @SpringBootTest 7 | class GitHubUnfollowerTrackerApplicationTests { 8 | 9 | @Test 10 | fun contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/kotlin/com/githubunfollowertracker/GitHubUnfollowerTrackerApplication.kt: -------------------------------------------------------------------------------- 1 | package com.githubunfollowertracker 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | import org.springframework.boot.runApplication 5 | 6 | @SpringBootApplication 7 | class GitHubUnfollowerTrackerApplication 8 | 9 | fun main(args: Array) { 10 | runApplication(*args) 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | application-dev.properties 9 | 10 | ### STS ### 11 | .apt_generated 12 | .classpath 13 | .factorypath 14 | .project 15 | .settings 16 | .springBeans 17 | .sts4-cache 18 | bin/ 19 | !**/src/main/**/bin/ 20 | !**/src/test/**/bin/ 21 | 22 | ### IntelliJ IDEA ### 23 | .idea 24 | *.iws 25 | *.iml 26 | *.ipr 27 | out/ 28 | !**/src/main/**/out/ 29 | !**/src/test/**/out/ 30 | 31 | ### NetBeans ### 32 | /nbproject/private/ 33 | /nbbuild/ 34 | /dist/ 35 | /nbdist/ 36 | /.nb-gradle/ 37 | 38 | ### VS Code ### 39 | .vscode/ 40 | 41 | ### Kotlin ### 42 | .kotlin 43 | -------------------------------------------------------------------------------- /src/main/kotlin/com/githubunfollowertracker/controller/ViewController.kt: -------------------------------------------------------------------------------- 1 | package com.githubunfollowertracker.controller 2 | 3 | import org.springframework.stereotype.Controller 4 | import org.springframework.web.bind.annotation.GetMapping 5 | 6 | /** 7 | * Controller responsible for managing view routing and displaying the main page. 8 | * This version has been simplified to only handle view routing to the 'main' template. 9 | */ 10 | @Controller 11 | class ViewController { 12 | 13 | /** 14 | * Endpoint to show the main page. 15 | * This method simply returns the name of the Thymeleaf template to render. 16 | * 17 | * @return The name of the Thymeleaf template ('main') to render. 18 | */ 19 | @GetMapping("/") 20 | fun showUnfollowPage(): String { 21 | return "main" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Application configuration properties 2 | 3 | # Name of the Spring Boot application 4 | spring.application.name=GitHubUnfollowerTracker 5 | 6 | # Server port configuration 7 | server.port=8090 8 | 9 | # Specifies the active profile for development environment 10 | spring.profiles.active=dev 11 | 12 | # OAuth2 GitHub provider configuration 13 | 14 | # Endpoint for GitHub OAuth2 authorization 15 | spring.security.oauth2.client.provider.github.authorization-uri=https://github.com/login/oauth/authorize 16 | # Endpoint for obtaining OAuth2 access token 17 | spring.security.oauth2.client.provider.github.token-uri=https://github.com/login/oauth/access_token 18 | # Endpoint for fetching user info 19 | spring.security.oauth2.client.provider.github.user-info-uri=https://api.github.com/user 20 | # Attribute name used for user identification 21 | spring.security.oauth2.client.provider.github.user-name-attribute=id 22 | -------------------------------------------------------------------------------- /src/main/kotlin/com/githubunfollowertracker/config/AppConfig.kt: -------------------------------------------------------------------------------- 1 | package com.githubunfollowertracker.config 2 | 3 | import okhttp3.OkHttpClient 4 | import org.springframework.context.annotation.Bean 5 | import org.springframework.context.annotation.Configuration 6 | import java.util.concurrent.TimeUnit 7 | 8 | /** 9 | * Configuration class to define application beans and configurations. 10 | */ 11 | @Configuration 12 | class AppConfig { 13 | 14 | /** 15 | * Bean definition for OkHttpClient with customized timeouts. 16 | * @return OkHttpClient instance 17 | */ 18 | @Bean 19 | fun okHttpClient(): OkHttpClient { 20 | return OkHttpClient.Builder() 21 | .connectTimeout(30, TimeUnit.SECONDS) // Set the connection timeout to 30 seconds 22 | .readTimeout(30, TimeUnit.SECONDS) // Set the socket read timeout to 30 seconds 23 | .writeTimeout(30, TimeUnit.SECONDS) // Set the socket write timeout to 30 seconds 24 | .build() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/kotlin/com/githubunfollowertracker/service/GetAccessTokenService.kt: -------------------------------------------------------------------------------- 1 | package com.githubunfollowertracker.service 2 | 3 | import org.springframework.security.oauth2.client.OAuth2AuthorizedClient 4 | import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService 5 | import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken 6 | import org.springframework.stereotype.Service 7 | 8 | /** 9 | * Service responsible for retrieving OAuth2 access tokens for GitHub API requests. 10 | */ 11 | @Service 12 | class GetAccessTokenService( 13 | private val clientService: OAuth2AuthorizedClientService // Service to manage OAuth2 clients 14 | ) { 15 | 16 | /** 17 | * Retrieves the access token from the provided OAuth2 authentication token. 18 | * 19 | * @param authentication The OAuth2 authentication token 20 | * @return The access token as a string, or null if not available 21 | */ 22 | fun getAccessToken(authentication: OAuth2AuthenticationToken): String? { 23 | val authorizedClient = clientService.loadAuthorizedClient( 24 | "github", authentication.name 25 | ) 26 | return authorizedClient?.accessToken?.tokenValue 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/kotlin/com/githubunfollowertracker/dto/GitHubUser.kt: -------------------------------------------------------------------------------- 1 | package com.githubunfollowertracker.dto 2 | 3 | /** 4 | * Data class representing GitHub user information retrieved from the GitHub API. 5 | * 6 | * @property login The GitHub user's login or username 7 | * @property id The unique identifier of the GitHub user 8 | * @property node_id The node ID of the GitHub user 9 | * @property avatar_url The URL of the GitHub user's avatar image 10 | * @property gravatar_id The Gravatar ID of the GitHub user 11 | * @property url The URL of the GitHub user's profile 12 | * @property html_url The HTML URL of the GitHub user's profile 13 | * @property followers_url The URL of the GitHub user's followers 14 | * @property following_url The URL of the GitHub user's following 15 | * @property gists_url The URL of the GitHub user's gists 16 | * @property starred_url The URL of the GitHub user's starred repositories 17 | * @property subscriptions_url The URL of the GitHub user's subscriptions 18 | * @property organizations_url The URL of the GitHub user's organizations 19 | * @property repos_url The URL of the GitHub user's repositories 20 | * @property events_url The URL of the GitHub user's events 21 | * @property received_events_url The URL of the GitHub user's received events 22 | * @property type The type of the GitHub user 23 | * @property site_admin A boolean indicating if the GitHub user is a site administrator 24 | */ 25 | data class GitHubUser( 26 | val login: String, 27 | val id: Long, 28 | val node_id: String, 29 | val avatar_url: String, 30 | val gravatar_id: String, 31 | val url: String, 32 | val html_url: String, 33 | val followers_url: String, 34 | val following_url: String, 35 | val gists_url: String, 36 | val starred_url: String, 37 | val subscriptions_url: String, 38 | val organizations_url: String, 39 | val repos_url: String, 40 | val events_url: String, 41 | val received_events_url: String, 42 | val type: String, 43 | val site_admin: Boolean 44 | ) -------------------------------------------------------------------------------- /src/main/kotlin/com/githubunfollowertracker/service/FollowMonitoringService.kt: -------------------------------------------------------------------------------- 1 | package com.githubunfollowertracker.service 2 | 3 | import com.githubunfollowertracker.dto.GitHubUser 4 | import com.google.gson.Gson 5 | import com.google.gson.reflect.TypeToken 6 | import okhttp3.OkHttpClient 7 | import okhttp3.Request 8 | import org.springframework.beans.factory.annotation.Value 9 | import org.springframework.stereotype.Service 10 | 11 | /** 12 | * Service responsible for fetching user following and followers lists from the GitHub API. 13 | */ 14 | @Service 15 | class FollowMonitoringService(private val httpClient: OkHttpClient, private val gson: Gson) { 16 | 17 | @Value("\${github.api.url}") 18 | private lateinit var githubApiUrl: String 19 | 20 | /** 21 | * Retrieves the list of users that the specified user is following. 22 | * 23 | * @param userName The GitHub username 24 | * @param credentials The OAuth2 access token for authentication 25 | * @return The list of GitHub users being followed 26 | */ 27 | fun getFollowingList(userName: String, credentials: String, page: Int): List { 28 | val url = "$githubApiUrl/users/$userName/following?per_page=12&page=$page" 29 | return makeApiCall(url, credentials) 30 | } 31 | 32 | /** 33 | * Retrieves the list of users following the specified user. 34 | * 35 | * @param userName The GitHub username 36 | * @param credentials The OAuth2 access token for authentication 37 | * @return The list of GitHub users who are followers 38 | */ 39 | fun getFollowersList(userName: String, credentials: String, page: Int): List { 40 | val url = "$githubApiUrl/users/$userName/followers?per_page=12&page=$page" 41 | return makeApiCall(url, credentials) 42 | } 43 | 44 | /** 45 | * Makes an API call to the specified URL with the provided OAuth2 access token. 46 | * 47 | * @param url The URL to make the API call to 48 | * @param credentials The OAuth2 access token for authentication 49 | * @return The list of GitHub users returned from the API call 50 | * @throws RuntimeException if the API call fails or the response is not successful 51 | */ 52 | private fun makeApiCall(url: String, credentials: String): List { 53 | val request = Request.Builder() 54 | .url(url) 55 | .header("Authorization", "Bearer $credentials") 56 | .get() 57 | .build() 58 | 59 | val response = httpClient.newCall(request).execute() 60 | val responseBody = response.body?.string() 61 | 62 | if (!response.isSuccessful || responseBody == null) 63 | throw RuntimeException("Failed to fetch data from GitHub, Response: $responseBody") 64 | 65 | val userListType = object : TypeToken>() {}.type 66 | return gson.fromJson(responseBody, userListType) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /src/main/kotlin/com/githubunfollowertracker/controller/GitHubController.kt: -------------------------------------------------------------------------------- 1 | package com.githubunfollowertracker.controller 2 | 3 | import com.githubunfollowertracker.dto.GitHubUser 4 | import com.githubunfollowertracker.service.FollowMonitoringService 5 | import com.githubunfollowertracker.service.GetAccessTokenService 6 | import com.githubunfollowertracker.service.GitHubService 7 | import kotlinx.coroutines.async 8 | import kotlinx.coroutines.awaitAll 9 | import kotlinx.coroutines.coroutineScope 10 | import org.springframework.beans.factory.annotation.Autowired 11 | import org.springframework.http.ResponseEntity 12 | import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken 13 | import org.springframework.web.bind.annotation.GetMapping 14 | import org.springframework.web.bind.annotation.PostMapping 15 | import org.springframework.web.bind.annotation.RequestParam 16 | import org.springframework.web.bind.annotation.RestController 17 | 18 | /** 19 | * This controller manages operations related to GitHub user interactions, 20 | * specifically focusing on following and unfollowing users. 21 | */ 22 | @RestController 23 | class GitHubController @Autowired constructor( 24 | private val gitHubService: GitHubService, // Handles interactions with GitHub API 25 | private val getAccessTokenService: GetAccessTokenService, // Retrieves OAuth2 access tokens 26 | private val followMonitoringService: FollowMonitoringService // Monitors follow and unfollow activities 27 | ) { 28 | 29 | /** 30 | * Unfollows users who do not reciprocate the follow back to the authenticated user, 31 | * considering an optional whitelist of users to remain following. 32 | * 33 | * @param oAuth2AuthenticationToken Provides the OAuth2 authentication context. 34 | * @param whiteList Optional list of usernames to be excluded from unfollowing. 35 | * @return A ResponseEntity with the result of the unfollow operation. 36 | */ 37 | @PostMapping("/unfollow") 38 | suspend fun unfollow( 39 | oAuth2AuthenticationToken: OAuth2AuthenticationToken, 40 | @RequestParam(required = false) whiteList: List = listOf() 41 | ): ResponseEntity = coroutineScope { 42 | val credentials = getAccessTokenService.getAccessToken(oAuth2AuthenticationToken) as String 43 | val userName = oAuth2AuthenticationToken.principal.attributes["login"] as String 44 | 45 | val following = gitHubService.fetchAllFollowing(userName, credentials).toSet() 46 | val followers = gitHubService.fetchAllFollowers(userName, credentials).toSet() 47 | val whiteListSet = whiteList.toSet() 48 | 49 | val unfollowActions = following.filterNot { it in followers || it in whiteListSet }.map { userToUnfollow -> 50 | async { 51 | gitHubService.unfollowUser(userName, userToUnfollow, credentials) 52 | } 53 | } 54 | unfollowActions.awaitAll() 55 | 56 | ResponseEntity.ok("Unfollowed non-followers successfully.") 57 | } 58 | 59 | /** 60 | * Retrieves a list of followers for the authenticated user. 61 | * 62 | * @param oAuth2AuthenticationToken Provides the OAuth2 authentication context. 63 | * @param page Specifies the pagination index for the followers list. 64 | * @return A ResponseEntity containing a list of GitHubUser representing followers. 65 | */ 66 | @GetMapping("/follower") 67 | fun followerList(oAuth2AuthenticationToken: OAuth2AuthenticationToken, 68 | @RequestParam page: Int): ResponseEntity> { 69 | val credentials = getAccessTokenService.getAccessToken(oAuth2AuthenticationToken) as String 70 | val userName = oAuth2AuthenticationToken.principal.attributes["login"] as String 71 | 72 | return ResponseEntity.ok(followMonitoringService.getFollowersList(userName, credentials, page)) 73 | } 74 | 75 | /** 76 | * Retrieves a list of users that the authenticated user is following. 77 | * 78 | * @param oAuth2AuthenticationToken Provides the OAuth2 authentication context. 79 | * @param page Specifies the pagination index for the following list. 80 | * @return A ResponseEntity containing a list of GitHubUser representing users being followed. 81 | */ 82 | @GetMapping("/following") 83 | fun followingList(oAuth2AuthenticationToken: OAuth2AuthenticationToken, 84 | @RequestParam page: Int): ResponseEntity> { 85 | val credentials = getAccessTokenService.getAccessToken(oAuth2AuthenticationToken) as String 86 | val userName = oAuth2AuthenticationToken.principal.attributes["login"] as String 87 | 88 | return ResponseEntity.ok(followMonitoringService.getFollowingList(userName, credentials, page)) 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![image](https://github.com/krkarma777/GitHubUnfollowerTracker/assets/149022496/bc8a1f23-b332-4320-92a3-0b4533ed4499) 2 | 3 | 4 | # GitHubUnfollowerTracker 5 | 6 | ## Project Description 7 | 8 | GitHubUnfollowerTracker is a sleek, web-based application that enables users to effectively manage and monitor their GitHub social connections. Leveraging the GitHub API, it provides real-time insights into follower dynamics, allowing users to identify who has unfollowed them and manage their following list more efficiently. This tool is built using Kotlin and Spring Boot, offering a responsive and user-friendly interface. 9 | 10 | === 11 | 12 | ### Version 2 Release Notes 13 | 14 | #### New Features 15 | - **Whitelist Management**: Users can now specify a whitelist of usernames to exempt from the unfollow process. This is done through a new input field in the Unfollow Users form, which supports comma-separated usernames. 16 | - **Asynchronous Processing**: Implemented asynchronous processing using Kotlin coroutines. This update includes: 17 | - **kotlinx-coroutines-core dependency**: Added for asynchronous processing capabilities. 18 | - **kotlinx-coroutines-reactor dependency**: Supports integration with Reactor for combining reactive programming with coroutines. 19 | - **Refactored `unfollowUser`**: Now utilizes coroutines to handle asynchronous execution, improving performance when processing multiple unfollow requests simultaneously. 20 | 21 | #### Enhancements 22 | - **Optimized Follower Filtering Logic**: Improved the logic for filtering followers in the unfollow endpoint, enhancing efficiency and response times. 23 | - **Enhanced Code Documentation**: Updated and expanded the code documentation for the `GitHubController`, making it easier to understand and maintain. 24 | 25 | #### Technical Improvements 26 | - Enhanced the stability and performance of the follower management tools. 27 | - Improved error handling for rate limit issues with GitHub's API. 28 | 29 | ### Known Issues 30 | - No major issues reported in this release. Users experiencing any difficulties should report them for immediate review. 31 | 32 | #### Upgrade Notes 33 | - Users are encouraged to update to the latest version to take advantage of the new features and improvements. 34 | - Ensure compatibility with existing deployments, especially concerning asynchronous operations and external API integrations. 35 | 36 | This release focuses on improving user control over social interactions on GitHub and optimizing backend operations for better performance and usability. 37 | 38 | === 39 | 40 | ## Features 41 | 42 | - **Monitor Unfollowers**: Instantly find out who has stopped following you. 43 | - **Manage Following List**: View and manage your current GitHub following list. 44 | - **Automatic Updates**: Stay informed with automatic updates reflecting any changes in your social graph. 45 | - **Enhanced User Interface**: Enjoy a modern interface that simplifies navigation and enhances user interaction. 46 | 47 | ## Getting Started 48 | 49 | These instructions will guide you through setting up the project on your local machine for development and testing purposes. 50 | 51 | ### Prerequisites 52 | 53 | - JDK 17 or newer 54 | - Spring Boot 3.2.5 55 | - Gradle or Maven as your build tool 56 | - GitHub API credentials 57 | 58 | ### Installation 59 | 60 | 1. **Clone the repository:** 61 | 62 | ```bash 63 | git clone https://github.com/yourusername/GitHubUnfollowerTracker.git 64 | cd GitHubUnfollowerTracker 65 | ``` 66 | 67 | 2. **Set up application properties:** 68 | 69 | Modify `src/main/resources/application-dev.properties` to include your GitHub API credentials: 70 | 71 | ```properties 72 | github.api.url=https://api.github.com 73 | 74 | # OAuth2 Client Configuration 75 | spring.security.oauth2.client.registration.github.client-id={your-client-id} 76 | spring.security.oauth2.client.registration.github.client-secret={your-client-secret} 77 | spring.security.oauth2.client.registration.github.scope=read:user, user:email, user:follow 78 | ``` 79 | 80 | 3. **Build the project:** 81 | 82 | Using Gradle: 83 | 84 | ```bash 85 | ./gradlew build 86 | ``` 87 | 88 | Or Maven: 89 | 90 | ```bash 91 | mvn clean install 92 | ``` 93 | 94 | 4. **Run the application:** 95 | 96 | ```bash 97 | ./gradlew bootRun 98 | ``` 99 | 100 | Or with Maven: 101 | 102 | ```bash 103 | mvn spring-boot:run 104 | ``` 105 | 106 | Visit `http://localhost:8090` in your browser. 107 | 108 | ## Usage 109 | 110 | Access the application by navigating to `http://localhost:8090` in your browser. Sign in using your GitHub credentials to authorize the application and start managing your follower and following lists. 111 | 112 | ## Contributing 113 | 114 | Contributions are welcome and greatly appreciated. Here’s how you can contribute: 115 | 116 | 1. Fork the Project 117 | 2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) 118 | 3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) 119 | 4. Push to the Branch (`git push origin feature/AmazingFeature`) 120 | 5. Open a Pull Request 121 | 122 | ## Acknowledgments 123 | 124 | - Hat tip to GitHub for the API used in this application. 125 | - A huge thank you to all contributors and the open-source community for continuous support. 126 | -------------------------------------------------------------------------------- /src/main/kotlin/com/githubunfollowertracker/service/GitHubService.kt: -------------------------------------------------------------------------------- 1 | package com.githubunfollowertracker.service 2 | 3 | import com.google.gson.Gson 4 | import com.google.gson.reflect.TypeToken 5 | import kotlinx.coroutines.Dispatchers 6 | import kotlinx.coroutines.withContext 7 | import okhttp3.OkHttpClient 8 | import okhttp3.Request 9 | import org.springframework.beans.factory.annotation.Value 10 | import org.springframework.stereotype.Service 11 | 12 | /** 13 | * Service class to handle interactions with the GitHub API. 14 | * Provides methods for fetching user's following list, followers list, and unfollowing users. 15 | */ 16 | @Service 17 | class GitHubService(private val httpClient: OkHttpClient, private val gson: Gson) { 18 | 19 | // Variable to store the base URL for the GitHub API. The value is set in application.properties. 20 | @Value("\${github.api.url}") 21 | private lateinit var githubApiUrl: String 22 | 23 | /** 24 | * Retrieves a complete list of users that the specified user is following. 25 | * This method pages through the GitHub API results until no more data is returned. 26 | * @param userName The username for which to fetch the complete following list 27 | * @param credentials The access token or credentials for authentication 28 | * @return Complete list of usernames that the specified user is following 29 | */ 30 | fun fetchAllFollowing(userName: String, credentials: String): List { 31 | var page = 1 // Start from the first page 32 | val allFollowing = mutableListOf() // Initialize an empty list to store all following users 33 | 34 | while (true) { 35 | val url = "$githubApiUrl/users/$userName/following?per_page=100&page=$page" // Construct URL with pagination 36 | val newFollowing = makeApiCall(url, credentials, "GET") // Fetch the following list for the page 37 | if (newFollowing.isEmpty()) { 38 | break // If no new users are found, end the loop 39 | } 40 | allFollowing.addAll(newFollowing) // Add the new users to the complete list 41 | page++ // Move to the next page 42 | } 43 | 44 | return allFollowing // Return the complete list of following users 45 | } 46 | 47 | /** 48 | * Retrieves a complete list of users who are followers of the specified user. 49 | * This method iterates over the GitHub API pages until it receives an empty response. 50 | * @param userName The username for which to fetch the complete followers list 51 | * @param credentials The access token or credentials for authentication 52 | * @return Complete list of usernames who are followers of the specified user 53 | */ 54 | fun fetchAllFollowers(userName: String, credentials: String): List { 55 | var page = 1 // Start from the first page 56 | val allFollowers = mutableListOf() // Initialize an empty list to store all followers 57 | 58 | while (true) { 59 | val url = "$githubApiUrl/users/$userName/followers?per_page=100&page=$page" // Construct URL with pagination 60 | val newFollowers = makeApiCall(url, credentials, "GET") // Fetch the followers list for the page 61 | if (newFollowers.isEmpty()) { 62 | break // If no new users are found, end the loop 63 | } 64 | allFollowers.addAll(newFollowers) // Add the new users to the complete list 65 | page++ // Move to the next page 66 | } 67 | 68 | return allFollowers // Return the complete list of followers 69 | } 70 | 71 | /** 72 | * Unfollows a user on behalf of the specified user. 73 | * @param userName The username of the authenticated user 74 | * @param userToUnfollow The username of the user to unfollow 75 | * @param credentials The access token or credentials for authentication 76 | */ 77 | suspend fun unfollowUser(userName: String, userToUnfollow: String, credentials: String) = withContext(Dispatchers.IO) { 78 | val url = "$githubApiUrl/user/following/$userToUnfollow" 79 | val request = Request.Builder() 80 | .url(url) 81 | .delete() 82 | .header("Authorization", "Bearer $credentials") 83 | .build() 84 | 85 | httpClient.newCall(request).execute().use { response -> 86 | if (!response.isSuccessful) 87 | throw RuntimeException("Failed to unfollow user: $userToUnfollow, Response: ${response.body?.string()}") 88 | } 89 | } 90 | 91 | /** 92 | * Helper method to make API calls to GitHub with the provided URL, credentials, and HTTP method. 93 | * @param url The URL for the API endpoint 94 | * @param credentials The access token or credentials for authentication 95 | * @param method The HTTP method (e.g., GET, POST, DELETE) 96 | * @return List of usernames retrieved from the API response 97 | */ 98 | private fun makeApiCall(url: String, credentials: String, method: String): List { 99 | val builder = Request.Builder() 100 | .url(url) 101 | .header("Authorization", "Bearer $credentials") 102 | 103 | // Construct the request based on the specified HTTP method 104 | val request = when (method) { 105 | "GET" -> builder.get().build() 106 | else -> throw IllegalArgumentException("Unsupported HTTP method: $method") 107 | } 108 | 109 | // Execute the request and handle response 110 | return httpClient.newCall(request).execute().use { response -> 111 | val responseBody = response.body?.string() 112 | if (!response.isSuccessful || responseBody == null) 113 | throw RuntimeException("Failed to fetch data from GitHub, Response: $responseBody") 114 | 115 | // Parse the response body and extract usernames 116 | val type = object : TypeToken>>() {}.type 117 | val result: List> = gson.fromJson(responseBody, type) 118 | return result.map { it["login"] ?: throw IllegalStateException("Unexpected GitHub API response format") } 119 | } 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/main/resources/templates/main.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Unfollow Users 7 | 119 | 120 | 121 | 124 |
125 |

Manage Your Followers

126 |

This tool helps you manage your GitHub following list by unfollowing users who do not reciprocate the follow, 127 | keeping your network optimized and relevant.

128 |
129 |
130 | 131 | 132 |
133 | 134 |
135 | 136 | 137 |
138 |

Following List

139 |
140 | 141 | 142 |
143 |

Followers List

144 |
145 |
146 | 232 | 233 | 234 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | --------------------------------------------------------------------------------