예제 #1
0
        private static async Task <string> ProcessInstallationAsync(Hook hook, CloudQueue routerMessages, CloudTable installationTable, ILogger logger)
        {
            switch (hook.action)
            {
            case "created":
                foreach (var repo in hook.repositories)
                {
                    await routerMessages.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(new RouterMessage
                    {
                        InstallationId = hook.installation.id,
                        Owner = hook.installation.account.login,
                        RepoName = repo.name,
                        CloneUrl = $"https://github.com/{repo.full_name}",
                    })));

                    logger.LogInformation("ProcessInstallationAsync/created: Added RouterMessage for {Owner}/{RepoName}", repo.owner, repo.name);
                }

                break;

            case "added":
                foreach (var repo in hook.repositories_added)
                {
                    await routerMessages.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(new RouterMessage
                    {
                        InstallationId = hook.installation.id,
                        Owner = hook.installation.account.login,
                        RepoName = repo.name,
                        CloneUrl = $"https://github.com/{repo.full_name}",
                    })));

                    logger.LogInformation("ProcessInstallationAsync/added: Added RouterMessage for {Owner}/{RepoName}", repo.owner, repo.name);
                }

                break;

            case "removed":
                foreach (var repo in hook.repositories_removed)
                {
                    await installationTable.DropRow(hook.installation.id.ToString(), repo.name);

                    logger.LogInformation("ProcessInstallationAsync/removed: DropRow for {InstallationId} :: {RepoName}", hook.installation.id, repo.name);
                }

                break;

            case "deleted":
                await installationTable.DropPartitionAsync(hook.installation.id.ToString());

                logger.LogInformation("ProcessInstallationAsync/deleted: DropPartition for {InstallationId}", hook.installation.id);
                break;
            }

            return("truth");
        }
예제 #2
0
        private static async Task <string> ProcessInstallationAsync(Hook hook, CloudTable marketplaceTable, CloudQueue routerMessages, CloudTable installationTable, ILogger logger)
        {
            var isPrivateEligible = false;

            if (hook.repositories?.Any(x => x.@private) == true || hook.repositories_added?.Any(x => x.@private) == true)
            {
                isPrivateEligible = await IsPrivateEligible(marketplaceTable, hook.installation.account.login);
            }

            switch (hook.action)
            {
            case "created":
                foreach (var repo in hook.repositories)
                {
                    if (repo.@private && !isPrivateEligible)
                    {
                        logger.LogError("ProcessInstallationAsync/added: Plan mismatch for {Owner}/{RepoName}", hook.installation.account.login, repo.name);
                        continue;
                    }

                    await routerMessages.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(new RouterMessage
                    {
                        InstallationId = hook.installation.id,
                        Owner = hook.installation.account.login,
                        RepoName = repo.name,
                        CloneUrl = $"https://github.com/{repo.full_name}",
                    })));

                    logger.LogInformation("ProcessInstallationAsync/created: Added RouterMessage for {Owner}/{RepoName}", hook.installation.account.login, repo.name);
                }

                break;

            case "added":
                foreach (var repo in hook.repositories_added)
                {
                    if (repo.@private && !isPrivateEligible)
                    {
                        logger.LogError("ProcessInstallationAsync/added: Plan mismatch for {Owner}/{RepoName}", hook.installation.account.login, repo.name);
                        continue;
                    }

                    await routerMessages.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(new RouterMessage
                    {
                        InstallationId = hook.installation.id,
                        Owner = hook.installation.account.login,
                        RepoName = repo.name,
                        CloneUrl = $"https://github.com/{repo.full_name}",
                    })));

                    logger.LogInformation("ProcessInstallationAsync/added: Added RouterMessage for {Owner}/{RepoName}", hook.installation.account.login, repo.name);
                }

                break;

            case "removed":
                foreach (var repo in hook.repositories_removed)
                {
                    await installationTable.DropRow(hook.installation.id.ToString(), repo.name);

                    logger.LogInformation("ProcessInstallationAsync/removed: DropRow for {InstallationId} :: {RepoName}", hook.installation.id, repo.name);
                }

                break;

            case "deleted":
                await installationTable.DropPartitionAsync(hook.installation.id.ToString());

                logger.LogInformation("ProcessInstallationAsync/deleted: DropPartition for {InstallationId}", hook.installation.id);
                break;
            }

            return("truth");
        }
예제 #3
0
        private static async Task <string> ProcessInstallationAsync(Hook hook, CloudTable marketplaceTable, CloudQueue routerMessages, CloudTable installationTable, ILogger logger)
        {
            var isPrivateEligible = false;
            var isOnAddedPlan     = false;
            int?usedPrivate       = 0;
            int?allowedPrivate    = 0;
            var privateRepo       = hook.repositories?.Any(x => x.@private) == true || hook.repositories_added?.Any(x => x.@private) == true;

            if (privateRepo)
            {
                (isOnAddedPlan, allowedPrivate, usedPrivate) = await IsOnAddedPlan(marketplaceTable, hook.installation.account.login);
            }

            if (!isOnAddedPlan && privateRepo)
            {
                isPrivateEligible = await IsPrivateEligible(marketplaceTable, hook.installation.account.login);
            }

            switch (hook.action)
            {
            case "created":

                foreach (var repo in hook.repositories)
                {
                    if (repo.@private && !isPrivateEligible && !isOnAddedPlan)
                    {
                        logger.LogError("ProcessInstallationAsync/added: Plan mismatch for {Owner}/{RepoName}", hook.installation.account.login, repo.name);
                        continue;
                    }

                    var compress = true;
                    if (repo.@private && isOnAddedPlan)
                    {
                        compress = false;
                        if (usedPrivate < allowedPrivate)
                        {
                            usedPrivate++;
                            await marketplaceTable.ExecuteAsync(TableOperation.InsertOrMerge(new Marketplace(hook.installation.account.id, hook.installation.account.login)
                            {
                                UsedPrivate = usedPrivate,
                            }));

                            compress = true;
                        }
                    }

                    await routerMessages.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(new RouterMessage
                    {
                        InstallationId = hook.installation.id,
                        Owner = hook.installation.account.login,
                        RepoName = repo.name,
                        CloneUrl = $"https://github.com/{repo.full_name}",
                        IsPrivate = repo.@private,
                        Compress = compress,
                    })));

                    logger.LogInformation("ProcessInstallationAsync/created: Added RouterMessage for {Owner}/{RepoName}", hook.installation.account.login, repo.name);
                }

                break;

            case "added":

                foreach (var repo in hook.repositories_added)
                {
                    if (repo.@private && !isPrivateEligible && !isOnAddedPlan)
                    {
                        logger.LogError("ProcessInstallationAsync/added: Plan mismatch for {Owner}/{RepoName}", hook.installation.account.login, repo.name);
                        continue;
                    }

                    var compress = true;
                    if (repo.@private && isOnAddedPlan)
                    {
                        compress = false;
                        if (usedPrivate < allowedPrivate)
                        {
                            usedPrivate++;
                            await marketplaceTable.ExecuteAsync(TableOperation.InsertOrMerge(new Marketplace(hook.installation.account.id, hook.installation.account.login)
                            {
                                UsedPrivate = usedPrivate,
                            }));

                            compress = true;
                        }
                    }

                    await routerMessages.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(new RouterMessage
                    {
                        InstallationId = hook.installation.id,
                        Owner = hook.installation.account.login,
                        RepoName = repo.name,
                        CloneUrl = $"https://github.com/{repo.full_name}",
                        IsPrivate = repo.@private,
                        Compress = compress,
                    })));

                    logger.LogInformation("ProcessInstallationAsync/added: Added RouterMessage for {Owner}/{RepoName}", hook.installation.account.login, repo.name);
                }

                break;

            case "removed":

                foreach (var repo in hook.repositories_removed)
                {
                    await installationTable.DropRow(hook.installation.id.ToString(), repo.name);

                    logger.LogInformation("ProcessInstallationAsync/removed: DropRow for {InstallationId} :: {RepoName}", hook.installation.id, repo.name);
                }

                break;

            case "deleted":

                await installationTable.DropPartitionAsync(hook.installation.id.ToString());

                logger.LogInformation("ProcessInstallationAsync/deleted: DropPartition for {InstallationId}", hook.installation.id);
                break;
            }

            return("truth");
        }