コード例 #1
0
        public override async Task <IActionResult> Create([FromBody, Required] v2018_07_16.Models.SubscriptionData subscription)
        {
            Data.Models.Channel channel = await _context.Channels.Where(c => c.Name == subscription.ChannelName)
                                          .FirstOrDefaultAsync();

            if (channel == null)
            {
                return(BadRequest(
                           new ApiError(
                               "the request is invalid",
                               new[] { $"The channel '{subscription.ChannelName}' could not be found." })));
            }

            Data.Models.Repository repo = await _context.Repositories.FindAsync(subscription.TargetRepository);

            if (subscription.TargetRepository.Contains("github.com"))
            {
                // If we have no repository information or an invalid installation id
                // then we will fail when trying to update things, so we fail early.
                if (repo == null || repo.InstallationId <= 0)
                {
                    return(BadRequest(
                               new ApiError(
                                   "the request is invalid",
                                   new[]
                    {
                        $"The repository '{subscription.TargetRepository}' does not have an associated github installation. " +
                        "The Maestro github application must be installed by the repository's owner and given access to the repository."
                    })));
                }
            }
            // In the case of a dev.azure.com repository, we don't have an app installation,
            // but we should add an entry in the repositories table, as this is required when
            // adding a new subscription policy.
            // NOTE:
            // There is a good chance here that we will need to also handle <account>.visualstudio.com
            // but leaving it out for now as it would be preferred to use the new format
            else if (subscription.TargetRepository.Contains("dev.azure.com"))
            {
                if (repo == null)
                {
                    _context.Repositories.Add(
                        new Data.Models.Repository
                    {
                        RepositoryName = subscription.TargetRepository,
                        InstallationId = default
                    });
コード例 #2
0
 public override Task <IActionResult> Create([FromBody, Required] v2018_07_16.Models.SubscriptionData subscription)
 {
     throw new NotImplementedException();
 }