-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0e4bfda
Showing
8 changed files
with
483 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# All paths default to 'scripts' which contains all script members | ||
* @AuroraEditor/scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Update Contributors List | ||
on: | ||
schedule: | ||
# Run every day of the week at 6am | ||
- cron: '0 6 * * *' | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
UpdateContributors: | ||
if: github.repository_owner == 'AuroraEditor' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Create config.json | ||
env: | ||
TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
echo "{ | ||
\"url\": \"https://api.github.com/users/AuroraEditor/repos\", | ||
\"token\": \"$TOKEN\", | ||
\"exclude\": [ | ||
\"ImgBotApp\", | ||
\"aurora-care-bear\", | ||
\"github-actions[bot]\", | ||
\"dependabot[bot]\", | ||
\"allcontributors[bot]\", | ||
\"actions-user\" | ||
] | ||
}" > config.json | ||
- name: Run & Send | ||
run: swift application.swift | ||
|
||
- name: Upload 'contributors.json' to repo | ||
run: | | ||
git config --global user.name 'aurora-care-bear' | ||
git config --global user.email '[email protected]' | ||
git remote set-url --push origin https://aurora-care-bear:[email protected]/AuroraEditor/AuroraEditorDiscordBot | ||
git add contributors.json | ||
git commit -m "Update Contributors (`date`)" | ||
git push origin HEAD:main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
config.ini | ||
config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
### MIT License | ||
|
||
Copyright (C) 2024 Aurora Company | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<p align="center"> | ||
<img alt="Logo" src="https://avatars.githubusercontent.com/u/106490518?s=128&v=4" width="128px;" height="128px;"> | ||
</p> | ||
|
||
<p align="center"> | ||
<h1 align="center">AuroraEditor Contributors Bot</h1> | ||
</p> | ||
|
||
<p align="center"> | ||
<a href='https://twitter.com/Aurora_Editor' target='_blank'> | ||
<img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/Aurora_Editor?color=f6579d&style=for-the-badge"> | ||
</a> | ||
<a href='https://discord.gg/5aecJ4rq9D' target='_blank'> | ||
<img alt="Discord" src="https://img.shields.io/discord/997410333348077620?color=f98a6c&style=for-the-badge"> | ||
</a> | ||
<a href='https://twitter.com/intent/tweet?text=Try%20this%20new%20open-source%20code%20editor,%20Aurora%20Editor&url=https://auroraeditor.com&via=Aurora_Editor&hashtags=AuroraEditor,editor,AEIDE,developers,Aurora,OSS' target='_blank'><img src='https://img.shields.io/twitter/url/http/shields.io.svg?style=social'></a> | ||
</p> | ||
|
||
<br /> | ||
|
||
> This is the repository for the Aurora Editor Contributors list. | ||
## Run | ||
|
||
create a config.json file in the root directory with the following contents: | ||
|
||
```json | ||
{ | ||
"url": "https://api.github.com/users/AuroraEditor/repos", | ||
"token": "GITHUB_TOKEN", | ||
"exclude": [ | ||
"ImgBotApp", | ||
"aurora-care-bear", | ||
"github-actions[bot]", | ||
"dependabot[bot]", | ||
"allcontributors[bot]", | ||
"actions-user" | ||
] | ||
} | ||
``` | ||
|
||
> **Note**\ | ||
> Change `GITHUB_TOKEN` to your own values. | ||
Run it using: | ||
|
||
```bash | ||
swift application.swift | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import Foundation | ||
|
||
#if canImport(FoundationNetworking) | ||
// Support network calls in Linux. | ||
import FoundationNetworking | ||
#endif | ||
|
||
/// Define the Contributor structure. | ||
/// | ||
/// This structure will hold the information about the contributors. | ||
/// | ||
/// Note: This is a class because of the need to update the contributions. | ||
/// | ||
/// - Parameters: | ||
/// - login: The GitHub login of the contributor. | ||
/// - avatar_url: The URL of the avatar of the contributor. | ||
/// - contributions: The number of contributions of the contributor. | ||
class Contributor: Codable { | ||
let login: String | ||
let avatar_url: String | ||
var contributions: Int | ||
|
||
init(login: String, avatar_url: String, contributions: Int) { | ||
self.login = login | ||
self.avatar_url = avatar_url | ||
self.contributions = contributions | ||
} | ||
} | ||
|
||
struct Configuration: Codable { | ||
let url: String | ||
let token: String | ||
let exclude: [String] | ||
} | ||
|
||
struct GitHubRepo: Codable { | ||
let name: String | ||
let contributors_url: String | ||
} | ||
|
||
// Fail if the config file doesn't exist. | ||
if !FileManager.default.fileExists(atPath: "config.json") { | ||
print("Config file not found.") | ||
exit(1) | ||
} | ||
|
||
// Load the configuration. | ||
let configuration = try JSONDecoder().decode( | ||
Configuration.self, | ||
from: Data(contentsOf: URL(fileURLWithPath: "config.json")) | ||
) | ||
|
||
var contributors: [Contributor] = [] | ||
|
||
// Load the data from GitHub. | ||
if let githubData: [GitHubRepo] = fetchData(url: configuration.url) { | ||
|
||
// Walk through the repos. | ||
for repo in githubData { | ||
// Parse the repo. | ||
print("Parsing \(repo.name)") | ||
parseRepo(repo: repo) | ||
} | ||
} else { | ||
print("Unable to parse the data from \(configuration.url)") | ||
} | ||
|
||
func parseRepo(repo: GitHubRepo) { | ||
// Get the contributors. | ||
|
||
guard let contributorsInRepo: [Contributor]? = fetchData( | ||
url: repo.contributors_url | ||
) else { | ||
print("Unable to parse the data from \(repo.contributors_url)") | ||
return | ||
} | ||
|
||
// Walk through the contributors. | ||
for contributor in contributorsInRepo ?? [] | ||
where configuration.exclude.contains(contributor.login) == false { | ||
// Check if the contributor is already in the list. | ||
if let selectedContributor = contributors.first(where: { | ||
$0.login == contributor.login | ||
}) { | ||
// Update the contributions. | ||
selectedContributor.contributions += contributor.contributions | ||
} else { | ||
// Add the contributor. | ||
contributors.append(.init( | ||
login: contributor.login, | ||
avatar_url: contributor.avatar_url, | ||
contributions: contributor.contributions | ||
)) | ||
} | ||
} | ||
} | ||
|
||
|
||
print("Contributors:") | ||
dump(contributors) | ||
|
||
// Encode the contributors to JSON. | ||
if let jsonData = try? JSONEncoder().encode(contributors) { | ||
// Write the data to a file. | ||
try? jsonData.write(to: URL(fileURLWithPath: "contributors.json")) | ||
} | ||
|
||
// WARNING: BAD PRACTICE, I'M FORCING THE PROGRAM TO WAIT FOR THE DATA. | ||
func fetchData<T: Codable>(url fromURL: String) -> T? { | ||
guard let url = URL(string: fromURL) else { | ||
print("Invalid URL") | ||
return nil | ||
} | ||
|
||
var wait = true | ||
var data: Data? | ||
|
||
var request = URLRequest(url: url) | ||
request.setValue("en", forHTTPHeaderField: "Accept-language") | ||
request.setValue("Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us)", forHTTPHeaderField: "User-Agent") | ||
|
||
if configuration.token != "" { | ||
request.setValue("Bearer \(configuration.token)", forHTTPHeaderField: "Authorization") | ||
} | ||
|
||
request.httpMethod = "GET" | ||
|
||
let task = URLSession.shared.dataTask(with: request) { ddata, response, error in | ||
guard | ||
let ddata = ddata, | ||
let response = response as? HTTPURLResponse, | ||
error == nil | ||
else { | ||
print("HTTP ERROR") | ||
print(error!.localizedDescription) | ||
wait = false | ||
return | ||
} | ||
|
||
guard (200 ... 299) ~= response.statusCode else { | ||
print("statusCode should be 2xx, but is \(response.statusCode)") | ||
print("response = \(response)") | ||
wait = false | ||
return | ||
} | ||
|
||
data = ddata | ||
wait = false | ||
} | ||
|
||
task.resume() | ||
|
||
while (wait) { } | ||
|
||
do { | ||
let json = try JSONDecoder().decode( | ||
T.self, | ||
from: data! | ||
) | ||
|
||
return json | ||
} catch { | ||
print(error) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Tell the OS that the program exited successfully. | ||
exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"url": "https://api.github.com/users/AuroraEditor/repos", | ||
"token": "GITHUB_TOKEN", | ||
"exclude": [ | ||
"ImgBotApp", | ||
"aurora-care-bear", | ||
"github-actions[bot]", | ||
"dependabot[bot]", | ||
"allcontributors[bot]", | ||
"actions-user" | ||
] | ||
} |
Oops, something went wrong.