Skip to content

Commit

Permalink
Merge pull request #1129 from imgbot/backup_queue
Browse files Browse the repository at this point in the history
Backup queue
  • Loading branch information
GrigoreMihai authored Mar 24, 2022
2 parents 5020c66 + e63879c commit b1cd054
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 33 deletions.
7 changes: 6 additions & 1 deletion Common/KnownGitHubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static class KnownGitHubs
// </remarks>
public const string AccessTokensUrlFormat = "https://api.github.com/app/installations/{0}/access_tokens";

public const int SmallestLimitPaidPlan = 5;
public const int SmallestLimitPaidPlan = 1;

// -1 for existing plans that include unlimited private
// -2 for old plans which also have unlimited private, that do not need marketplacesync
Expand All @@ -44,6 +44,11 @@ public static readonly ReadOnlyDictionary<int, int> Plans
{ 6921, 50 },
{ 6922, 100 },
{ 6923, 200 },
{ 7386, 1 },
{ 7387, 3 },
{ 7388, 10 },
{ 7389, 25 },
{ 7390, 100 },
});
}
}
11 changes: 11 additions & 0 deletions Common/Messages/BackupMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Common.Messages
{
public class BackupMessage
{
public int PlanId { get; set; }

public string SaleType { get; set; }

public int Price { get; set; }
}
}
2 changes: 2 additions & 0 deletions Common/TableModels/Marketplace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public Marketplace(int accountId, string accountLogin)
public int? AllowedPrivate { get; set; }

public int? UsedPrivate { get; set; }

public bool? FreeTrial { get; set; }
}
}
4 changes: 2 additions & 2 deletions CompressImagesFunction/host.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"version": "2.0",
"functionTimeout": "01:00:00",
"functionTimeout": "02:00:00",
"logging": {
"fileLoggingMode": "never"
},
"extensions": {
"queues": {
"batchSize": 4
"batchSize": 2
}
}
}
52 changes: 37 additions & 15 deletions Test/WebHookTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public async Task GivenCommitToOtherBranch_ShouldReturnOkDoNothing()
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -65,7 +66,8 @@ public async Task GivenCommitToDefaultBranchNoImages_ShouldReturnOkDoNothing()
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -98,7 +100,8 @@ public async Task GivenCommitToImgBotBranchByImgbot_ShouldReturnOkQueueToOpenPr(
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -134,7 +137,8 @@ public async Task GivenCommitToImgBotBranchByOthers_ShouldReturnOkDoNothing()
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -167,7 +171,8 @@ public async Task GivenCommitToDefaultBranchWithImages_ShouldReturnOkQueueToRout
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -224,6 +229,7 @@ void ExtraSetup(
out var installationsTable,
out var marketplaceTable,
out var settingsTable,
out var backupMessages,
ExtraSetup);

// Assert OKObjectResult and Value
Expand Down Expand Up @@ -261,7 +267,8 @@ public async Task GivenCommitToDefaultBranchWithConfig_ShouldReturnOkQueueToRout
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -298,7 +305,8 @@ public async Task GivenCommitToDefaultBranchWithImagesUppercaseExtensions_Should
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -335,7 +343,8 @@ public async Task GivenNewInstallationAdded_ShouldReturnOkQueueRouter()
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -372,7 +381,8 @@ public async Task GivenNewInstallationCreated_ShouldReturnOkQueueRouter()
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -428,6 +438,7 @@ void ExtraSetup(
out var installationsTable,
out var marketplaceTable,
out var settingsTable,
out var backupMessages,
ExtraSetup);

// Assert OKObjectResult and Value
Expand Down Expand Up @@ -483,6 +494,7 @@ void ExtraSetup(
out var installationsTable,
out var marketplaceTable,
out var settingsTable,
out var backupMessages,
ExtraSetup);

// Assert OKObjectResult and Value
Expand Down Expand Up @@ -516,7 +528,8 @@ public async Task GivenMarketplacePurchase_ShouldReturnOkWriteRow()
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -569,6 +582,7 @@ void ExtraSetup(
out var installationsTable,
out var marketplaceTable,
out var settingsTable,
out var backupMessages,
ExtraSetup);

// Assert OKObjectResult and Value
Expand Down Expand Up @@ -603,7 +617,8 @@ public async Task GivenMergedImgBotToDefaultBranch_ShouldReturnOkQueueToDeleteBr
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -660,6 +675,7 @@ void ExtraSetup(
out var installationsTable,
out var marketplaceTable,
out var settingsTable,
out var backupMessages,
ExtraSetup);

// Assert OKObjectResult and Value
Expand Down Expand Up @@ -697,7 +713,8 @@ public async Task GivenMergedImgBotToOtherBranch_ShouldReturnOkDoNothing()
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -730,7 +747,8 @@ public async Task GivenSquashMergedImgBotToDefaultBranch_ShouldReturnOkQueueToDe
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -767,7 +785,8 @@ public async Task GivenRebaseMergedImgBotToDefaultBranch_ShouldReturnOkQueueToDe
out var deleteBranchMessages,
out var installationsTable,
out var marketplaceTable,
out var settingsTable);
out var settingsTable,
out var backupMessages);

// Assert OKObjectResult and Value
var response = (HookResponse)((OkObjectResult)result).Value;
Expand Down Expand Up @@ -802,6 +821,7 @@ private Task<IActionResult> ExecuteHookAsync(
out CloudTable installationsTable,
out CloudTable marketplaceTable,
out CloudTable settingsTable,
out CloudQueue backupMessages,
Action<CloudQueue, CloudQueue, CloudTable, CloudTable, CloudTable> extraSetup = null)
{
var request = Substitute.For<HttpRequestMessage>();
Expand All @@ -811,6 +831,8 @@ private Task<IActionResult> ExecuteHookAsync(
installationsTable = Substitute.For<CloudTable>(new Uri("https://myaccount.table.core.windows.net/Tables/installation"));
marketplaceTable = Substitute.For<CloudTable>(new Uri("https://myaccount.table.core.windows.net/Tables/marketplace"));
settingsTable = Substitute.For<CloudTable>(new Uri("https://myaccount.table.core.windows.net/Tables/settings"));
backupMessages = Substitute.For<CloudQueue>(new Uri("https://myaccount.queue.core.windows.net/Queue/backup"));

var logger = Substitute.For<ILogger>();

request.Headers.Add("X-GitHub-Event", new[] { githubEvent });
Expand All @@ -819,7 +841,7 @@ private Task<IActionResult> ExecuteHookAsync(
extraSetup?.Invoke(routerMessages, openPrMessages, installationsTable, marketplaceTable, settingsTable);

return WebHook.WebHookFunction.Run(
request, routerMessages, openPrMessages, deleteBranchMessages, installationsTable, marketplaceTable, settingsTable, logger);
request, routerMessages, openPrMessages, deleteBranchMessages, installationsTable, marketplaceTable, settingsTable, backupMessages, logger);
}
}
}
2 changes: 1 addition & 1 deletion Web/src/app/vue/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<div class="col-11 col-lg offset-lg-1">
<p>
<img alt src="/images/128x128_circle.png" width="30" />
Imgbot &copy; 2017-2020
Imgbot &copy; 2017-2022
</p>
</div>
<div class="col-11 col-lg">
Expand Down
34 changes: 27 additions & 7 deletions Web/src/app/vue/components/Installation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ export default {
case 6894:
return 'Starter'
case 6919:
case 7386:
return 'Team'
case 6920:
case 7387:
return 'Agency'
case 6921:
case 7388:
return 'Enterprise'
case 6922:
case 7389:
return 'Gold'
case 6923:
case 7390:
return 'Platinium'
}
Expand All @@ -98,35 +103,50 @@ export default {
case 6921:
case 6922:
case 6927:
case 7386:
case 7387:
case 7388:
case 7389:
return 'Upgrade plan'
case 1750:
case 2840:
case 2841:
case 6923:
case 7390:
return 'Downgrade plan'
}
},
changePlanLink: function() {
switch (this.installation.planId) {
case 1749:
case 6927:
return `https://github.com/marketplace/imgbot/upgrade/6/${this.installation.accountid}`
return `https://github.com/marketplace/imgbot/upgrade/13/${this.installation.accountid}`
case 1750:
case 2840:
case 2841:
return `https://github.com/marketplace/imgbot/upgrade/12/${this.installation.accountid}`
case 6894:
return `https://github.com/marketplace/imgbot/upgrade/7/${this.installation.accountid}`
return `https://github.com/marketplace/imgbot/upgrade/13/${this.installation.accountid}`
case 6919:
return `https://github.com/marketplace/imgbot/upgrade/8/${this.installation.accountid}`
return `https://github.com/marketplace/imgbot/upgrade/14/${this.installation.accountid}`
case 6920:
return `https://github.com/marketplace/imgbot/upgrade/9/${this.installation.accountid}`
return `https://github.com/marketplace/imgbot/upgrade/15/${this.installation.accountid}`
case 6921:
return `https://github.com/marketplace/imgbot/upgrade/10/${this.installation.accountid}`
return `https://github.com/marketplace/imgbot/upgrade/16/${this.installation.accountid}`
case 6922:
return `https://github.com/marketplace/imgbot/upgrade/11/${this.installation.accountid}`
return `https://github.com/marketplace/imgbot/upgrade/17/${this.installation.accountid}`
case 6923:
return `https://github.com/marketplace/imgbot/upgrade/10/${this.installation.accountid}`
return `https://github.com/marketplace/imgbot/upgrade/16/${this.installation.accountid}`
case 7386:
return `https://github.com/marketplace/imgbot/upgrade/14/${this.installation.accountid}`
case 7387:
return `https://github.com/marketplace/imgbot/upgrade/15/${this.installation.accountid}`
case 7388:
return `https://github.com/marketplace/imgbot/upgrade/16/${this.installation.accountid}`
case 7389:
return `https://github.com/marketplace/imgbot/upgrade/17/${this.installation.accountid}`
case 7390:
return `https://github.com/marketplace/imgbot/upgrade/16/${this.installation.accountid}`
}
},
filteredRepositories: function() {
Expand Down
2 changes: 1 addition & 1 deletion Web/src/app/vue/components/Repository.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default {
return 'undefined';
},
addedPlan: function() {
return [ 6894, 6919, 6920, 6921, 6922,6923 ].includes(this.planId);
return [ 6894, 6919, 6920, 6921, 6922,6923,7386,7387,7388,7389,7390 ].includes(this.planId);
}
},
methods: {
Expand Down
2 changes: 1 addition & 1 deletion Web/src/github-students/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ <h3>Policies</h3>
<div class="col-11 col-lg offset-lg-1">
<p>
<img alt="" src="/images/128x128_circle.png" width="30" />
Imgbot &copy; 2017-2019
Imgbot &copy; 2017-2022
</p>
</div>
<div class="col-11 col-lg">
Expand Down
2 changes: 1 addition & 1 deletion Web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ <h3>Policies</h3>
<div class="col-11 col-lg offset-lg-1">
<p>
<img alt="" src="/images/128x128_circle.png" width="30" />
Imgbot &copy; 2017-2019
Imgbot &copy; 2017-2022
</p>
</div>
<div class="col-11 col-lg">
Expand Down
2 changes: 1 addition & 1 deletion Web/src/info/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h3>Policies</h3>
<div class="col-11 col-lg offset-lg-1">
<p>
<img alt="" src="/images/128x128_circle.png" width="30" />
Imgbot &copy; 2017-2019
Imgbot &copy; 2017-2022
</p>
</div>
<div class="col-11 col-lg">
Expand Down
2 changes: 1 addition & 1 deletion Web/src/winning/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ <h3>Policies</h3>
<div class="col-11 col-lg offset-lg-1">
<p>
<img alt="" src="/images/128x128_circle.png" width="30" />
Imgbot &copy; 2017-2019
Imgbot &copy; 2017-2022
</p>
</div>
<div class="col-11 col-lg">
Expand Down
Loading

0 comments on commit b1cd054

Please sign in to comment.