Skip to content

Commit c42bbf9

Browse files
authored
Merge pull request #78 from gitcomteam/release/minor
v0.19.0-rc7
2 parents b33f4cd + 61c6f78 commit c42bbf9

File tree

8 files changed

+78
-42
lines changed

8 files changed

+78
-42
lines changed

App/AL/AppBoot.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using App.DL.Module.Cache;
3-
using Micron.DL.Model;
43

54
namespace App.AL {
65
public static class AppBoot {

App/AL/Schedule/Project/Post/SyncReleases.cs

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,46 +28,40 @@ public SyncReleases() {
2828
var githubToken = AppConfig.GetConfiguration("auth:external:github:token");
2929
if (githubToken != null) githubClient.Credentials = new Credentials(githubToken);
3030

31-
int pageIndex = 1;
32-
var repos = Repo.Paginate(pageIndex);
31+
var repos = Repo.GetRandom(50);
3332

34-
while (repos.Length > 0) {
35-
foreach (var repo in repos) {
33+
foreach (var repo in repos) {
34+
try {
35+
if (repo.service_type != RepoServiceType.GitHub) continue;
36+
var splitUrl = repo.repo_url.Split("/");
37+
IEnumerable<Release> releases;
3638
try {
37-
if (repo.service_type != RepoServiceType.GitHub) continue;
38-
var splitUrl = repo.repo_url.Split("/");
39-
IEnumerable<Release> releases;
40-
try {
41-
releases = githubClient.Repository.Release.GetAll(
42-
splitUrl[3], splitUrl[4]
43-
).Result.OrderBy(x => x.Id);
44-
}
45-
catch (Exception e) {
46-
continue; // ignored
47-
}
39+
releases = githubClient.Repository.Release.GetAll(
40+
splitUrl[3], splitUrl[4]
41+
).Result.OrderBy(x => x.Id);
42+
}
43+
catch (Exception e) {
44+
continue; // ignored
45+
}
4846

49-
foreach (var release in releases) {
50-
if (release.Body.Length < 100) continue;
47+
foreach (var release in releases) {
48+
if (release.Body.Length < 100) continue;
5149

52-
var existingPost = ProjectPost.FindBy("origin_id", release.Id.ToString());
53-
if (existingPost != null) continue;
50+
var existingPost = ProjectPost.FindBy("origin_id", release.Id.ToString());
51+
if (existingPost != null) continue;
5452

55-
var post = ProjectPost.Create(
56-
repo.Project(), $"Released {release.Name}", release.Body
57-
);
58-
post.UpdateCol("origin_id", release.Id.ToString());
59-
post.UpdateCol(
60-
"created_at", release.PublishedAt.Value.ToUnixTimeSeconds().ToString()
61-
);
62-
}
63-
}
64-
catch (Exception e) {
65-
SentrySdk.CaptureException(e);
53+
var post = ProjectPost.Create(
54+
repo.Project(), $"Released {release.Name}", release.Body
55+
);
56+
post.UpdateCol("origin_id", release.Id.ToString());
57+
post.UpdateCol(
58+
"created_at", release.PublishedAt.Value.ToUnixTimeSeconds().ToString()
59+
);
6660
}
6761
}
68-
69-
++pageIndex;
70-
repos = Repo.Paginate(pageIndex);
62+
catch (Exception e) {
63+
SentrySdk.CaptureException(e);
64+
}
7165
}
7266
});
7367
JobsPool.Get().Push(task);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Net.Http;
4+
using System.Threading.Tasks;
5+
using Micron.DL.Module.Config;
6+
7+
namespace App.AL.Utils.External.Discord {
8+
public static class DiscordWebhooks {
9+
public static void SendEvent(string type, string content) {
10+
Task.Run(() => {
11+
var client = new HttpClient();
12+
client.DefaultRequestHeaders.Add("Accept", "application/json");
13+
14+
var webhookUrl = AppConfig.GetConfiguration($"external:discord:webhook_tokens:{type}");
15+
16+
if (string.IsNullOrEmpty(webhookUrl)) return;
17+
18+
var response = client.PostAsync(
19+
webhookUrl,
20+
new FormUrlEncodedContent(new[] {
21+
new KeyValuePair<string, string>("content", content),
22+
})
23+
).Result;
24+
});
25+
}
26+
}
27+
}

App/DL/Model/Repo/Repo.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public static Repo Find(string originId, RepoServiceType type)
5555
$"SELECT * FROM repositories WHERE origin_id = @origin_id AND service_type = '{type.ToString()}' LIMIT 1",
5656
new {origin_id = originId}
5757
).FirstOrDefault();
58+
59+
public static Repo[] GetRandom(int limit = 10)
60+
=> Connection().Query<Repo>(
61+
"SELECT * FROM repositories ORDER BY random() LIMIT @limit", new {limit}
62+
).ToArray();
5863

5964
public static Repo[] Paginate(int page, int size = 20)
6065
=> Connection().Query<Repo>(
@@ -84,8 +89,10 @@ public Repo Save() {
8489
return this;
8590
}
8691

87-
public Octokit.Repository GithubRepo() =>
88-
GitHubApi.Client().Repository.Get(Convert.ToInt64(origin_id)).Result;
92+
public Octokit.Repository GithubRepo() {
93+
var originId = Convert.ToInt64(origin_id == "" ? "0" : origin_id);
94+
return GitHubApi.Client().Repository.Get(originId).Result;
95+
}
8996

9097
public Project.Project Project() => Model.Project.Project.FindBy("repository_id", id);
9198

App/DL/Repository/Alias/ProjectAliasRepository.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ public static ProjectAlias Create(Model.Project.Project project) {
2626
var alias = PrepareAlias(project.name);
2727

2828
var creator = project.Creator();
29-
var owner = creator != null ?
30-
PrepareAlias(creator.login) : PrepareAlias(project.Repository().GithubRepo().Owner.Login);
29+
30+
var owner = creator != null ? PrepareAlias(creator.login) : "_";
31+
#if !DEBUG
32+
if (creator == null) owner = PrepareAlias(project.Repository().GithubRepo().Owner.Login);
33+
#endif
3134

3235
var newAlias = alias;
3336
var postfix = 0;

App/DL/Repository/Funding/InvoiceRepository.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using App.AL.Utils.External.Discord;
12
using App.DL.Enum;
23
using App.DL.Model.Funding;
34
using App.DL.Repository.User;
@@ -18,7 +19,9 @@ public static Invoice Create(
1819
UserBalanceRepository.FindOrCreate(user, currencyType);
1920
break;
2021
}
21-
return Find(Invoice.Create(user, entityId, entityType, amount, currencyType, status, wallet));
22+
var invoice = Find(Invoice.Create(user, entityId, entityType, amount, currencyType, status, wallet));
23+
DiscordWebhooks.SendEvent("system-events", $"New invoice #{invoice.id} was created for user: {invoice.user_id}");
24+
return invoice;
2225
}
2326

2427
public static Invoice UpdateStatus(Invoice invoice, InvoiceStatus status) {

App/DL/Repository/User/UserRepository.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using App.AL.Utils.External.Discord;
12
using App.DL.Enum;
23
using App.DL.Model.Funding;
34
using App.DL.Model.User;
@@ -58,7 +59,7 @@ public static UserModel FindOrCreateByEmailAndLogin(
5859
}
5960

6061
user ??= Create(email, login, password);
61-
62+
6263
UserBadge.Create(user, "Early adopter");
6364

6465
int tokenRegisterBonus = System.Convert.ToInt32(
@@ -78,7 +79,9 @@ public static UserModel FindOrCreateByEmailAndLogin(
7879
}
7980

8081
public static UserModel Create(string email, string login, string password) {
81-
return Find(UserModel.Create(email, login, password));
82+
var newUserId = UserModel.Create(email, login, password);
83+
DiscordWebhooks.SendEvent("system-events", $"New user #{newUserId} just signed up! Email: {email}");
84+
return Find(newUserId);
8285
}
8386
}
8487
}

docker/build_and_push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ docker build -t registry.gitlab.com/mxss/gitcom-api/gitcom-backend:"$1" -f docke
1010
echo "Pushing image to registy"
1111
docker push registry.gitlab.com/mxss/gitcom-api/gitcom-backend:"$1"
1212

13-
echo "Done. version $1 is built and pushed."
13+
echo "Done. version $1 is built and pushed."

0 commit comments

Comments
 (0)