├── .dockerignore ├── .gitignore ├── .rspec ├── .ruby-version ├── .tool-versions ├── .travis.yml ├── Aptfile ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dockerfile ├── Dockerfile.tcie ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── Makefile ├── Procfile ├── README.md ├── Rakefile ├── bin ├── cron ├── migrate-hooks ├── start-nginx ├── suspend ├── unsuspend ├── user_mgmt.rb └── users ├── config.ru ├── config ├── mime.types ├── nginx.conf.erb ├── puma-config.rb ├── ruby_config.sh └── unicorn.rb ├── knapsack_rspec_report.json ├── lib ├── patches │ └── active_record │ │ └── predicate_builder.rb ├── tasks │ ├── build_update_branch.rake │ ├── build_update_pull_request_data.rake │ ├── correct_next_runs_for_crons.rake │ ├── enable_repo_migration.rake │ ├── encrypt_all_data.rake │ ├── populate_dont_run_if_recent_build_exists.rake │ └── populate_next_and_last_runs_for_crons.rake ├── travis.rb └── travis │ ├── api │ ├── app.rb │ ├── app │ │ ├── access_token.rb │ │ ├── base.rb │ │ ├── cors.rb │ │ ├── endpoint.rb │ │ ├── endpoint │ │ │ ├── accounts.rb │ │ │ ├── authorization.rb │ │ │ ├── branches.rb │ │ │ ├── broadcasts.rb │ │ │ ├── build_backups.rb │ │ │ ├── builds.rb │ │ │ ├── documentation.rb │ │ │ ├── endpoints.rb │ │ │ ├── env_vars.rb │ │ │ ├── error.rb │ │ │ ├── home.rb │ │ │ ├── hooks.rb │ │ │ ├── jobs.rb │ │ │ ├── lint.rb │ │ │ ├── logout.rb │ │ │ ├── logs.rb │ │ │ ├── pusher.rb │ │ │ ├── repos.rb │ │ │ ├── requests.rb │ │ │ ├── setting_endpoint.rb │ │ │ ├── singleton_settings_endpoint.rb │ │ │ ├── slow.rb │ │ │ ├── uptime.rb │ │ │ └── users.rb │ │ ├── error_handling.rb │ │ ├── extensions.rb │ │ ├── extensions │ │ │ ├── expose_pattern.rb │ │ │ ├── scoping.rb │ │ │ ├── smart_constants.rb │ │ │ └── subclass_tracker.rb │ │ ├── helpers.rb │ │ ├── helpers │ │ │ ├── accept.rb │ │ │ ├── current_user.rb │ │ │ ├── db_follower.rb │ │ │ ├── flash.rb │ │ │ ├── mime_types.rb │ │ │ └── respond_with.rb │ │ ├── middleware.rb │ │ ├── middleware │ │ │ ├── error_handler.rb │ │ │ ├── honeycomb.rb │ │ │ ├── log_tracing.rb │ │ │ ├── logging.rb │ │ │ ├── metriks.rb │ │ │ ├── opencensus.rb │ │ │ ├── request_id.rb │ │ │ ├── rewrite.rb │ │ │ ├── scope_check.rb │ │ │ └── user_agent_tracker.rb │ │ ├── responders.rb │ │ ├── responders │ │ │ ├── atom.rb │ │ │ ├── badge.rb │ │ │ ├── base.rb │ │ │ ├── image.rb │ │ │ ├── json.rb │ │ │ ├── plain.rb │ │ │ ├── service.rb │ │ │ └── xml.rb │ │ ├── schedulers │ │ │ └── schedule_cron_jobs.rb │ │ └── services │ │ │ └── schedule_request.rb │ ├── attack.rb │ ├── enqueue │ │ └── services │ │ │ ├── cancel_model.rb │ │ │ └── restart_model.rb │ ├── serialize.rb │ ├── serialize │ │ ├── formats.rb │ │ ├── serializer.rb │ │ ├── serializer.rb_ │ │ ├── v0.rb │ │ ├── v0 │ │ │ ├── event.rb │ │ │ ├── event │ │ │ │ ├── build.rb │ │ │ │ └── job.rb │ │ │ ├── notification.rb │ │ │ ├── notification │ │ │ │ ├── build.rb │ │ │ │ ├── repository.rb │ │ │ │ └── user.rb │ │ │ ├── pusher.rb │ │ │ ├── pusher │ │ │ │ ├── build.rb │ │ │ │ ├── build │ │ │ │ │ ├── canceled.rb │ │ │ │ │ ├── created.rb │ │ │ │ │ ├── finished.rb │ │ │ │ │ ├── received.rb │ │ │ │ │ ├── received │ │ │ │ │ │ └── job.rb │ │ │ │ │ ├── started.rb │ │ │ │ │ └── started │ │ │ │ │ │ └── job.rb │ │ │ │ ├── job.rb │ │ │ │ └── job │ │ │ │ │ ├── canceled.rb │ │ │ │ │ ├── created.rb │ │ │ │ │ ├── finished.rb │ │ │ │ │ ├── received.rb │ │ │ │ │ └── started.rb │ │ │ ├── worker.rb │ │ │ └── worker │ │ │ │ ├── job.rb │ │ │ │ └── job │ │ │ │ └── test.rb │ │ ├── v1.rb │ │ ├── v1 │ │ │ ├── archive.rb │ │ │ ├── archive │ │ │ │ ├── build.rb │ │ │ │ └── build │ │ │ │ │ └── job.rb │ │ │ ├── helpers.rb │ │ │ ├── helpers │ │ │ │ └── legacy.rb │ │ │ ├── http.rb │ │ │ ├── http │ │ │ │ ├── branches.rb │ │ │ │ ├── build.rb │ │ │ │ ├── build │ │ │ │ │ └── job.rb │ │ │ │ ├── builds.rb │ │ │ │ ├── hooks.rb │ │ │ │ ├── job.rb │ │ │ │ ├── jobs.rb │ │ │ │ ├── repositories.rb │ │ │ │ ├── repository.rb │ │ │ │ └── user.rb │ │ │ ├── webhook.rb │ │ │ └── webhook │ │ │ │ ├── build.rb │ │ │ │ └── build │ │ │ │ ├── finished.rb │ │ │ │ └── finished │ │ │ │ └── job.rb │ │ ├── v2.rb │ │ └── v2 │ │ │ ├── http.rb │ │ │ └── http │ │ │ ├── account_env_var.rb │ │ │ ├── accounts.rb │ │ │ ├── branch.rb │ │ │ ├── branches.rb │ │ │ ├── broadcasts.rb │ │ │ ├── build.rb │ │ │ ├── builds.rb │ │ │ ├── caches.rb │ │ │ ├── env_var.rb │ │ │ ├── env_vars.rb │ │ │ ├── error.rb │ │ │ ├── hooks.rb │ │ │ ├── job.rb │ │ │ ├── jobs.rb │ │ │ ├── permissions.rb │ │ │ ├── remote_log.rb │ │ │ ├── repositories.rb │ │ │ ├── repository.rb │ │ │ ├── request.rb │ │ │ ├── requests.rb │ │ │ ├── ssh_key.rb │ │ │ ├── ssl_key.rb │ │ │ ├── user.rb │ │ │ └── validation_error.rb │ ├── sidekiq.rb │ ├── v3.rb │ └── v3 │ │ ├── access_control.rb │ │ ├── access_control │ │ ├── anonymous.rb │ │ ├── application.rb │ │ ├── generic.rb │ │ ├── internal.rb │ │ ├── legacy_token.rb │ │ ├── log_token.rb │ │ ├── org_token.rb │ │ ├── scoped.rb │ │ ├── signature.rb │ │ └── user.rb │ │ ├── authorizer.rb │ │ ├── billing_client.rb │ │ ├── collection_renderer.rb │ │ ├── com_api_client.rb │ │ ├── config_obfuscator.rb │ │ ├── constant_resolver.rb │ │ ├── error.rb │ │ ├── extensions │ │ ├── belongs_to.rb │ │ └── preferences.rb │ │ ├── gdpr_client.rb │ │ ├── github.rb │ │ ├── log_token.rb │ │ ├── metrics.rb │ │ ├── model.rb │ │ ├── model_renderer.rb │ │ ├── models.rb │ │ ├── models │ │ ├── account_env_var.rb │ │ ├── admin_setting.rb │ │ ├── admin_settings.rb │ │ ├── allowance.rb │ │ ├── audit.rb │ │ ├── auto_refill.rb │ │ ├── beta_feature.rb │ │ ├── beta_migration_request.rb │ │ ├── billing_permissions.rb │ │ ├── branch.rb │ │ ├── broadcast.rb │ │ ├── build.rb │ │ ├── build_backup.rb │ │ ├── build_permission.rb │ │ ├── bulk_change_result.rb │ │ ├── cache.rb │ │ ├── commit.rb │ │ ├── coupon.rb │ │ ├── credits_calculator_config.rb │ │ ├── credits_result.rb │ │ ├── cron.rb │ │ ├── custom_key.rb │ │ ├── email.rb │ │ ├── email_unsubscribe.rb │ │ ├── env_var.rb │ │ ├── env_vars.rb │ │ ├── executions.rb │ │ ├── fingerprint.rb │ │ ├── installation.rb │ │ ├── invoice.rb │ │ ├── job.rb │ │ ├── jobs_stats.rb │ │ ├── json_pair.rb │ │ ├── json_slice.rb │ │ ├── json_sync.rb │ │ ├── key_pair.rb │ │ ├── log.rb │ │ ├── mailer.rb │ │ ├── membership.rb │ │ ├── message.rb │ │ ├── organization.rb │ │ ├── organization_preferences.rb │ │ ├── organization_token.rb │ │ ├── organization_token_permission.rb │ │ ├── owner.rb │ │ ├── permission.rb │ │ ├── plan.rb │ │ ├── plan_share.rb │ │ ├── preference.rb │ │ ├── pull_request.rb │ │ ├── remote_log.rb │ │ ├── repository.rb │ │ ├── repository_migration.rb │ │ ├── request.rb │ │ ├── scan_result.rb │ │ ├── scanner_collection.rb │ │ ├── settings.rb │ │ ├── ssl_key.rb │ │ ├── stage.rb │ │ ├── star.rb │ │ ├── storage.rb │ │ ├── subscription.rb │ │ ├── tag.rb │ │ ├── token.rb │ │ ├── trial.rb │ │ ├── user.rb │ │ ├── user_beta_feature.rb │ │ ├── user_preferences.rb │ │ ├── user_setting.rb │ │ ├── user_settings.rb │ │ ├── user_utm_param.rb │ │ ├── v2_addon.rb │ │ ├── v2_addon_usage.rb │ │ ├── v2_plan_config.rb │ │ ├── v2_subscription.rb │ │ └── v2_trial.rb │ │ ├── opt_in.rb │ │ ├── paginator.rb │ │ ├── paginator │ │ ├── count_cache.rb │ │ ├── efficient_pagination_url_generator.rb │ │ └── url_generator.rb │ │ ├── permissions.rb │ │ ├── permissions │ │ ├── account_env_var.rb │ │ ├── build.rb │ │ ├── cron.rb │ │ ├── env_var.rb │ │ ├── generic.rb │ │ ├── job.rb │ │ ├── key_pair.rb │ │ ├── log.rb │ │ ├── organization.rb │ │ ├── preferences.rb │ │ ├── repository.rb │ │ ├── ssl_key.rb │ │ ├── subscription.rb │ │ ├── trial.rb │ │ ├── user.rb │ │ └── user_setting.rb │ │ ├── proxy_service.rb │ │ ├── queries.rb │ │ ├── queries │ │ ├── access_token.rb │ │ ├── account_env_var.rb │ │ ├── allowance.rb │ │ ├── beta_feature.rb │ │ ├── beta_features.rb │ │ ├── beta_migration_request.rb │ │ ├── beta_migration_requests.rb │ │ ├── branch.rb │ │ ├── branches.rb │ │ ├── broadcasts.rb │ │ ├── build.rb │ │ ├── build_backup.rb │ │ ├── build_backups.rb │ │ ├── build_permissions.rb │ │ ├── builds.rb │ │ ├── caches.rb │ │ ├── coupons.rb │ │ ├── credits_calculator.rb │ │ ├── cron.rb │ │ ├── crons.rb │ │ ├── custom_key.rb │ │ ├── email_subscription.rb │ │ ├── enterprise_license.rb │ │ ├── env_var.rb │ │ ├── env_vars.rb │ │ ├── executions.rb │ │ ├── gdpr.rb │ │ ├── installation.rb │ │ ├── invoices.rb │ │ ├── job.rb │ │ ├── jobs.rb │ │ ├── key_pair.rb │ │ ├── lint.rb │ │ ├── log.rb │ │ ├── messages.rb │ │ ├── organization.rb │ │ ├── organizations.rb │ │ ├── owner.rb │ │ ├── plans.rb │ │ ├── preference.rb │ │ ├── preferences.rb │ │ ├── repositories.rb │ │ ├── repository.rb │ │ ├── repository_vcs.rb │ │ ├── request.rb │ │ ├── request_preview.rb │ │ ├── requests.rb │ │ ├── scan_result.rb │ │ ├── scan_results.rb │ │ ├── ssl_key.rb │ │ ├── stages.rb │ │ ├── storage.rb │ │ ├── subscription.rb │ │ ├── subscriptions.rb │ │ ├── trials.rb │ │ ├── user.rb │ │ ├── user_setting.rb │ │ ├── user_settings.rb │ │ ├── users.rb │ │ ├── v2_addon_usages.rb │ │ ├── v2_invoices.rb │ │ ├── v2_plans.rb │ │ ├── v2_subscription.rb │ │ └── v2_subscriptions.rb │ │ ├── query.rb │ │ ├── recaptcha_client.rb │ │ ├── remote_query.rb │ │ ├── renderer.rb │ │ ├── renderer │ │ ├── accepted.rb │ │ ├── access_token.rb │ │ ├── account_env_var.rb │ │ ├── active.rb │ │ ├── allowance.rb │ │ ├── auto_refill.rb │ │ ├── avatar_url.rb │ │ ├── beta_feature.rb │ │ ├── beta_features.rb │ │ ├── beta_migration_request.rb │ │ ├── beta_migration_requests.rb │ │ ├── branch.rb │ │ ├── branches.rb │ │ ├── broadcast.rb │ │ ├── broadcasts.rb │ │ ├── build.rb │ │ ├── build_backup.rb │ │ ├── build_backups.rb │ │ ├── build_permission.rb │ │ ├── build_permissions.rb │ │ ├── builds.rb │ │ ├── bulk_change_result.rb │ │ ├── cache.rb │ │ ├── caches.rb │ │ ├── commit.rb │ │ ├── coupon.rb │ │ ├── credits_calculator_config.rb │ │ ├── credits_result.rb │ │ ├── credits_results.rb │ │ ├── cron.rb │ │ ├── crons.rb │ │ ├── custom_key.rb │ │ ├── enterprise_license.rb │ │ ├── env_var.rb │ │ ├── env_vars.rb │ │ ├── error.rb │ │ ├── execution.rb │ │ ├── execution_per_repo.rb │ │ ├── execution_per_sender.rb │ │ ├── executions.rb │ │ ├── executions_per_repo.rb │ │ ├── executions_per_sender.rb │ │ ├── installation.rb │ │ ├── invoice.rb │ │ ├── invoices.rb │ │ ├── job.rb │ │ ├── job_config.rb │ │ ├── jobs.rb │ │ ├── jobs_stats.rb │ │ ├── key_pair.rb │ │ ├── lint.rb │ │ ├── log.rb │ │ ├── message.rb │ │ ├── messages.rb │ │ ├── organization.rb │ │ ├── organizations.rb │ │ ├── owner.rb │ │ ├── plan.rb │ │ ├── plan_share.rb │ │ ├── plan_shares.rb │ │ ├── plans.rb │ │ ├── preference.rb │ │ ├── preferences.rb │ │ ├── proxy.rb │ │ ├── repositories.rb │ │ ├── repository.rb │ │ ├── request.rb │ │ ├── request_config.rb │ │ ├── request_preview.rb │ │ ├── request_raw_configuration.rb │ │ ├── requests.rb │ │ ├── scan_result.rb │ │ ├── scan_results.rb │ │ ├── ssl_key.rb │ │ ├── stage.rb │ │ ├── stages.rb │ │ ├── storage.rb │ │ ├── subscription.rb │ │ ├── subscriptions.rb │ │ ├── tag.rb │ │ ├── trial.rb │ │ ├── trials.rb │ │ ├── user.rb │ │ ├── user_beta_feature.rb │ │ ├── user_setting.rb │ │ ├── user_settings.rb │ │ ├── users.rb │ │ ├── v2_addon.rb │ │ ├── v2_addon_config.rb │ │ ├── v2_addon_usage.rb │ │ ├── v2_addon_usages.rb │ │ ├── v2_plan_config.rb │ │ ├── v2_plans.rb │ │ ├── v2_subscription.rb │ │ ├── v2_subscriptions.rb │ │ └── v2_trial.rb │ │ ├── result.rb │ │ ├── result │ │ └── head.rb │ │ ├── router.rb │ │ ├── routes.rb │ │ ├── routes │ │ ├── dsl.rb │ │ └── resource.rb │ │ ├── scanner_client.rb │ │ ├── service.rb │ │ ├── service_index.rb │ │ ├── services.rb │ │ └── services │ │ ├── access_token │ │ ├── regenerate_token.rb │ │ └── remove_token.rb │ │ ├── account_env_var │ │ └── delete.rb │ │ ├── account_env_vars │ │ └── create.rb │ │ ├── active │ │ ├── for_current_user.rb │ │ └── for_owner.rb │ │ ├── allowance │ │ └── for_owner.rb │ │ ├── beta_feature │ │ ├── delete.rb │ │ └── update.rb │ │ ├── beta_features │ │ └── find.rb │ │ ├── beta_migration_request │ │ └── proxy_create.rb │ │ ├── beta_migration_requests │ │ ├── create.rb │ │ ├── find.rb │ │ └── proxy_find.rb │ │ ├── branch │ │ └── find.rb │ │ ├── branches │ │ └── find.rb │ │ ├── broadcasts │ │ └── for_current_user.rb │ │ ├── build │ │ ├── cancel.rb │ │ ├── find.rb │ │ ├── priority.rb │ │ └── restart.rb │ │ ├── build_backup │ │ └── find.rb │ │ ├── build_backups │ │ └── all.rb │ │ ├── build_permissions │ │ ├── find_for_organization.rb │ │ ├── find_for_repo.rb │ │ ├── update_for_organization.rb │ │ └── update_for_repo.rb │ │ ├── builds │ │ ├── find.rb │ │ └── for_current_user.rb │ │ ├── caches │ │ ├── delete.rb │ │ └── find.rb │ │ ├── coupons │ │ └── find.rb │ │ ├── credits_calculator │ │ ├── calculator.rb │ │ └── default_config.rb │ │ ├── cron │ │ ├── create.rb │ │ ├── delete.rb │ │ ├── find.rb │ │ └── for_branch.rb │ │ ├── crons │ │ └── for_repository.rb │ │ ├── custom_key │ │ └── delete.rb │ │ ├── custom_keys │ │ └── create.rb │ │ ├── email_subscription │ │ ├── resubscribe.rb │ │ └── unsubscribe.rb │ │ ├── enterprise_license │ │ └── find.rb │ │ ├── env_var │ │ ├── delete.rb │ │ ├── find.rb │ │ └── update.rb │ │ ├── env_vars │ │ ├── create.rb │ │ └── for_repository.rb │ │ ├── executions │ │ ├── for_owner.rb │ │ ├── for_owner_per_repo.rb │ │ └── for_owner_per_sender.rb │ │ ├── gdpr │ │ ├── export.rb │ │ └── purge.rb │ │ ├── insights │ │ ├── active_repos.rb │ │ ├── insights_proxy.rb │ │ └── metrics.rb │ │ ├── installation │ │ └── find.rb │ │ ├── job │ │ ├── cancel.rb │ │ ├── debug.rb │ │ ├── find.rb │ │ └── restart.rb │ │ ├── jobs │ │ ├── find.rb │ │ └── for_current_user.rb │ │ ├── key_pair │ │ ├── create.rb │ │ ├── delete.rb │ │ ├── find.rb │ │ └── update.rb │ │ ├── lint │ │ └── lint.rb │ │ ├── log │ │ ├── delete.rb │ │ └── find.rb │ │ ├── messages │ │ └── for_request.rb │ │ ├── organization │ │ ├── find.rb │ │ ├── suspend.rb │ │ ├── sync.rb │ │ ├── unsuspend.rb │ │ ├── update_billing_permission.rb │ │ └── user_activity.rb │ │ ├── organizations │ │ └── for_current_user.rb │ │ ├── owner │ │ └── find.rb │ │ ├── plans │ │ └── all.rb │ │ ├── preference │ │ ├── find.rb │ │ ├── for_organization.rb │ │ └── update.rb │ │ ├── preferences │ │ ├── for_organization.rb │ │ └── for_user.rb │ │ ├── queues │ │ └── stats.rb │ │ ├── repositories │ │ ├── for_current_user.rb │ │ └── for_owner.rb │ │ ├── repository │ │ ├── activate.rb │ │ ├── deactivate.rb │ │ ├── find.rb │ │ ├── migrate.rb │ │ ├── settings.rb │ │ ├── star.rb │ │ ├── unstar.rb │ │ └── update.rb │ │ ├── repository_vcs │ │ └── find.rb │ │ ├── request │ │ ├── find.rb │ │ └── preview.rb │ │ ├── requests │ │ ├── create.rb │ │ └── find.rb │ │ ├── scan_result │ │ └── find.rb │ │ ├── scan_results │ │ └── all.rb │ │ ├── ssl_key │ │ ├── create.rb │ │ └── find.rb │ │ ├── stages │ │ └── find.rb │ │ ├── storage │ │ ├── delete.rb │ │ ├── find.rb │ │ └── update.rb │ │ ├── subscription │ │ ├── cancel.rb │ │ ├── invoices.rb │ │ ├── pause.rb │ │ ├── pay.rb │ │ ├── resubscribe.rb │ │ ├── update_address.rb │ │ ├── update_creditcard.rb │ │ ├── update_payment_details.rb │ │ └── update_plan.rb │ │ ├── subscriptions │ │ ├── all.rb │ │ └── create.rb │ │ ├── trials │ │ ├── all.rb │ │ └── create.rb │ │ ├── user │ │ ├── current.rb │ │ ├── find.rb │ │ ├── logout.rb │ │ ├── sync.rb │ │ └── update.rb │ │ ├── user_setting │ │ ├── find.rb │ │ └── update.rb │ │ ├── user_settings │ │ └── for_repository.rb │ │ ├── users │ │ ├── suspend.rb │ │ └── unsuspend.rb │ │ ├── v2_plans │ │ └── all.rb │ │ ├── v2_subscription │ │ ├── auto_refill.rb │ │ ├── buy_addon.rb │ │ ├── cancel.rb │ │ ├── changetofree_plan.rb │ │ ├── invoices.rb │ │ ├── pause.rb │ │ ├── pay.rb │ │ ├── share.rb │ │ ├── toggle_auto_refill.rb │ │ ├── update_address.rb │ │ ├── update_auto_refill.rb │ │ ├── update_creditcard.rb │ │ ├── update_payment_details.rb │ │ ├── update_plan.rb │ │ └── user_usages.rb │ │ └── v2_subscriptions │ │ ├── all.rb │ │ └── create.rb │ ├── config │ └── defaults.rb │ ├── errors.rb │ ├── event.rb │ ├── event │ ├── config.rb │ ├── handler.rb │ ├── handler │ │ ├── metrics.rb │ │ └── trail.rb │ └── subscription.rb │ ├── features.rb │ ├── github.rb │ ├── github │ ├── education.rb │ ├── oauth.rb │ ├── services.rb │ └── services │ │ ├── set_hook.rb │ │ └── set_key.rb │ ├── honeycomb.rb │ ├── marginalia.rb │ ├── model.rb │ ├── model │ ├── account.rb │ ├── branch.rb │ ├── broadcast.rb │ ├── build.rb │ ├── build │ │ ├── config.rb │ │ ├── config │ │ │ ├── dist.rb │ │ │ ├── env.rb │ │ │ ├── features.rb │ │ │ ├── group.rb │ │ │ ├── language.rb │ │ │ ├── matrix.rb │ │ │ ├── obfuscate.rb │ │ │ ├── os.rb │ │ │ └── yaml.rb │ │ ├── denormalize.rb │ │ ├── matrix.rb │ │ ├── metrics.rb │ │ ├── result_message.rb │ │ ├── states.rb │ │ └── update_branch.rb │ ├── build_backup.rb │ ├── commit.rb │ ├── email.rb │ ├── encrypted_column.rb │ ├── env_helpers.rb │ ├── job.rb │ ├── job │ │ ├── cleanup.rb │ │ ├── queue.rb │ │ └── test.rb │ ├── membership.rb │ ├── organization.rb │ ├── owner_group.rb │ ├── permission.rb │ ├── pull_request.rb │ ├── remote_log.rb │ ├── repository.rb │ ├── repository │ │ ├── settings.rb │ │ └── status_image.rb │ ├── request.rb │ ├── scope_access.rb │ ├── ssl_key.rb │ ├── subscription.rb │ ├── token.rb │ ├── url.rb │ ├── user.rb │ └── user │ │ ├── oauth.rb │ │ └── renaming.rb │ ├── notification.rb │ ├── notification │ ├── instrument.rb │ ├── instrument │ │ ├── event_handler.rb │ │ └── task.rb │ ├── publisher.rb │ └── publisher │ │ ├── log.rb │ │ ├── memory.rb │ │ └── redis.rb │ ├── private_key.rb │ ├── remote_log.rb │ ├── remote_vcs │ ├── client.rb │ ├── repository.rb │ ├── response_error.rb │ └── user.rb │ ├── request_deadline.rb │ ├── secure_config.rb │ ├── services.rb │ ├── services │ ├── base.rb │ ├── delete_caches.rb │ ├── find_admin.rb │ ├── find_branch.rb │ ├── find_branches.rb │ ├── find_build.rb │ ├── find_build_backups.rb │ ├── find_builds.rb │ ├── find_caches.rb │ ├── find_hooks.rb │ ├── find_job.rb │ ├── find_jobs.rb │ ├── find_log.rb │ ├── find_repo.rb │ ├── find_repo_key.rb │ ├── find_repo_settings.rb │ ├── find_repos.rb │ ├── find_request.rb │ ├── find_requests.rb │ ├── find_user_accounts.rb │ ├── find_user_broadcasts.rb │ ├── find_user_permissions.rb │ ├── helpers.rb │ ├── next_build_number.rb │ ├── regenerate_repo_key.rb │ ├── registry.rb │ ├── remove_log.rb │ ├── sync_user.rb │ ├── update_hook.rb │ ├── update_job.rb │ └── update_user.rb │ ├── sidekiq.rb │ ├── states_cache.rb │ ├── task.rb │ ├── testing.rb │ └── testing │ ├── factories.rb │ ├── matchers.rb │ ├── payloads.rb │ ├── scenario.rb │ ├── stubs.rb │ └── stubs │ └── stub.rb ├── public ├── favicon.ico └── images │ └── result │ ├── canceled.png │ ├── canceled.svg │ ├── error.png │ ├── error.svg │ ├── failing.png │ ├── failing.svg │ ├── passing.png │ ├── passing.svg │ ├── pending.png │ ├── pending.svg │ ├── unknown.png │ └── unknown.svg ├── script ├── console ├── monitor-pgbouncer ├── repos_stats.rb ├── request ├── server ├── server-buildpacks └── web_concurrency ├── spec ├── auth │ ├── helpers.rb │ ├── helpers │ │ ├── faraday.rb │ │ ├── rack_test.rb │ │ └── shared.rb │ ├── report │ │ ├── README │ │ ├── auth.csv │ │ ├── auth.html │ │ ├── csv_formatter.rb │ │ ├── generate │ │ ├── table.erb │ │ └── table.rb │ ├── v1 │ │ ├── accounts_spec.rb │ │ ├── branches_spec.rb │ │ ├── broadcasts_spec.rb │ │ ├── builds_spec.rb │ │ ├── env_vars_spec.rb │ │ ├── hooks_spec.rb │ │ ├── jobs_spec.rb │ │ ├── logs_spec.rb │ │ ├── repo_status_spec.rb │ │ ├── repos_spec.rb │ │ ├── requests_spec.rb │ │ ├── ssh_keys_spec.rb │ │ └── users_spec.rb │ ├── v2.1 │ │ ├── accounts_spec.rb │ │ ├── branches_spec.rb │ │ ├── broadcasts_spec.rb │ │ ├── builds_spec.rb │ │ ├── env_vars_spec.rb │ │ ├── hooks_spec.rb │ │ ├── jobs_spec.rb │ │ ├── logs_spec.rb │ │ ├── repo_status_spec.rb │ │ ├── repos_spec.rb │ │ ├── requests_spec.rb │ │ ├── ssh_keys_spec.rb │ │ ├── switch_spec.rb │ │ └── users_spec.rb │ └── v2 │ │ ├── accounts_spec.rb │ │ ├── branches_spec.rb │ │ ├── broadcasts_spec.rb │ │ ├── builds_spec.rb │ │ ├── env_vars_spec.rb │ │ ├── hooks_spec.rb │ │ ├── jobs_spec.rb │ │ ├── logs_spec.rb │ │ ├── repo_status_spec.rb │ │ ├── repos_spec.rb │ │ ├── requests_spec.rb │ │ ├── ssh_keys_spec.rb │ │ └── users_spec.rb ├── integration │ ├── error_handling_spec.rb │ ├── formats_handling_spec.rb │ ├── scopes_spec.rb │ ├── settings_endpoint_spec.rb │ ├── singleton_settings_endpoint_spec.rb │ ├── uptime_spec.rb │ ├── v1 │ │ └── repositories_spec.rb │ ├── v2 │ │ ├── accounts_spec.rb │ │ ├── branches_spec.rb │ │ ├── builds_spec.rb │ │ ├── hooks_spec.rb │ │ ├── jobs_spec.rb │ │ ├── pusher_spec.rb │ │ ├── repositories_spec.rb │ │ ├── requests_spec.rb │ │ ├── settings │ │ │ ├── env_vars_spec.rb │ │ │ └── ssh_key_spec.rb │ │ └── users_spec.rb │ ├── v2_spec.backup.rb │ ├── version_spec.rb │ └── visibility_spec.rb ├── lib │ ├── github │ │ ├── oauth_spec.rb │ │ └── services │ │ │ └── set_key_spec.rb │ ├── model │ │ ├── broadcast_spec.rb │ │ ├── build │ │ │ ├── config │ │ │ │ ├── dist_spec.rb │ │ │ │ ├── group_spec.rb │ │ │ │ ├── matrix_spec.rb │ │ │ │ └── obfuscate_spec.rb │ │ │ ├── config_spec.rb │ │ │ ├── denormalize_spec.rb │ │ │ ├── matrix_spec.rb │ │ │ ├── metrics_spec.rb │ │ │ ├── result_message_spec.rb │ │ │ └── states_spec.rb │ │ ├── build_spec.rb │ │ ├── commit_spec.rb │ │ ├── encrypted_column_spec.rb │ │ ├── job │ │ │ ├── cleanup_spec.rb │ │ │ ├── queue_spec.rb │ │ │ └── test_spec.rb │ │ ├── job_spec.rb │ │ ├── organization_spec.rb │ │ ├── permission_spec.rb │ │ ├── repository │ │ │ ├── settings │ │ │ │ └── ssh_key_spec.rb │ │ │ ├── settings_spec.rb │ │ │ └── status_image_spec.rb │ │ ├── repository_spec.rb │ │ ├── request_spec.rb │ │ ├── ssl_key_spec.rb │ │ ├── token_spec.rb │ │ ├── url_spec.rb │ │ ├── user │ │ │ └── oauth_spec.rb │ │ └── user_spec.rb │ ├── schedulers │ │ └── schedule_cron_jobs_spec.rb │ ├── services │ │ ├── find_admin_spec.rb │ │ ├── find_branch_spec.rb │ │ ├── find_branches_spec.rb │ │ ├── find_build_spec.rb │ │ ├── find_builds_spec.rb │ │ ├── find_caches_spec.rb │ │ ├── find_hooks_spec.rb │ │ ├── find_job_spec.rb │ │ ├── find_jobs_spec.rb │ │ ├── find_log_spec.rb │ │ ├── find_repo_key_spec.rb │ │ ├── find_repo_settings_spec.rb │ │ ├── find_repo_spec.rb │ │ ├── find_repos_spec.rb │ │ ├── find_request_spec.rb │ │ ├── find_requests_spec.rb │ │ ├── find_user_accounts_spec.rb │ │ ├── next_build_number_spec.rb │ │ ├── regenerate_repo_key_spec.rb │ │ ├── remove_log_spec.rb │ │ ├── sync_user_spec.rb │ │ ├── update_hook_spec.rb │ │ ├── update_job_spec.rb │ │ └── update_user_spec.rb │ ├── services_spec.rb │ └── travis │ │ ├── api │ │ └── enqueue │ │ │ └── services │ │ │ └── restart_model_spec.rb │ │ ├── config_spec.rb │ │ └── remote_log_spec.rb ├── spec_helper.rb ├── support.rb ├── support │ ├── active_record.rb │ ├── billing_spec_helper.rb │ ├── coverage.rb │ ├── enterprise_license.json │ ├── env.rb │ ├── formats.rb │ ├── gcs.rb │ ├── gdpr_spec_helper.rb │ ├── github_apps.rb │ ├── matchers.rb │ ├── payloads.rb │ ├── private_key.rb │ ├── s3.rb │ ├── scanner_spec_helper.rb │ ├── shared_examples.rb │ ├── ssl_keys.rb │ └── test_helpers.rb ├── travis │ └── remote_vcs │ │ ├── repository_spec.rb │ │ └── user_spec.rb ├── unit │ ├── access_token_spec.rb │ ├── app_spec.rb │ ├── attack_spec.rb │ ├── cors_spec.rb │ ├── default_spec.rb │ ├── endpoint │ │ ├── accounts_spec.rb │ │ ├── authorization │ │ │ └── user_manager_spec.rb │ │ ├── authorization_spec.rb │ │ ├── branches_spec.rb │ │ ├── builds_spec.rb │ │ ├── endpoints_spec.rb │ │ ├── hooks_spec.rb │ │ ├── lint_spec.rb │ │ ├── logs_id_spec.rb │ │ ├── logs_spec.rb │ │ ├── repos_spec.rb │ │ ├── requests │ │ │ └── throttle_spec.rb │ │ └── users_spec.rb │ ├── endpoint_spec.rb │ ├── extensions │ │ ├── expose_pattern_spec.rb │ │ ├── scoping_spec.rb │ │ ├── smart_constants_spec.rb │ │ └── subclass_tracker_spec.rb │ ├── helpers │ │ ├── accept_spec.rb │ │ └── json_renderer_spec.rb │ ├── middleware │ │ ├── logging_spec.rb │ │ ├── scope_check_spec.rb │ │ └── user_agent_tracker_spec.rb │ ├── model │ │ ├── build_spec.rb │ │ ├── job_spec.rb │ │ ├── organization_spec.rb │ │ └── user_spec.rb │ ├── responders │ │ ├── json_spec.rb │ │ └── service_spec.rb │ └── serialize │ │ └── v2 │ │ └── http │ │ ├── accounts_spec.rb │ │ ├── branch_spec.rb │ │ ├── branches_spec.rb │ │ ├── broadcasts_spec.rb │ │ ├── build_spec.rb │ │ ├── builds_spec.rb │ │ ├── caches_spec.rb │ │ ├── env_var_spec.rb │ │ ├── hooks_spec.rb │ │ ├── job_spec.rb │ │ ├── jobs_spec.rb │ │ ├── permissions_spec.rb │ │ ├── repositories_spec.rb │ │ ├── repository_spec.rb │ │ ├── request_spec.rb │ │ ├── requests_spec.rb │ │ ├── ssl_key_spec.rb │ │ └── user_spec.rb └── v3 │ ├── billing_client_spec.rb │ ├── config_obfuscator_spec.rb │ ├── error_handling_spec.rb │ ├── extensions │ └── belongs_to_spec.rb │ ├── metrics_spec.rb │ ├── models │ ├── branch_spec.rb │ ├── build_backup_spec.rb │ ├── build_spec.rb │ ├── credits_calculator_config_spec.rb │ ├── credits_result_spec.rb │ ├── cron_spec.rb │ ├── custom_key_spec.rb │ ├── fingerprint_spec.rb │ ├── job_spec.rb │ ├── mailer_spec.rb │ ├── repository_migration_spec.rb │ ├── repository_spec.rb │ ├── scanner_collection_spec.rb │ ├── subscription_spec.rb │ └── v2_subscription_spec.rb │ ├── queries │ ├── build_backup_spec.rb │ ├── build_backups_spec.rb │ ├── build_permissions_spec.rb │ ├── custom_key_spec.rb │ ├── organization_spec.rb │ └── user_spec.rb │ ├── renderer │ ├── avatar_url_spec.rb │ ├── build_backup_spec.rb │ └── repository_spec.rb │ ├── result_spec.rb │ ├── router_spec.rb │ ├── scanner_client_spec.rb │ ├── service_index_spec.rb │ ├── service_spec.rb │ └── services │ ├── access_token │ ├── regenerate_token_spec.rb │ └── remove_token_spec.rb │ ├── account_env_var │ ├── create_spec.rb │ └── delete_spec.rb │ ├── active │ └── for_owner_spec.rb │ ├── allowance │ └── for_owner_spec.rb │ ├── beta_feature │ ├── delete_spec.rb │ └── update_spec.rb │ ├── beta_features │ └── find_spec.rb │ ├── beta_migration_request │ └── proxy_create_spec.rb │ ├── beta_migration_requests │ ├── create_spec.rb │ └── proxy_find_spec.rb │ ├── branch │ └── find_spec.rb │ ├── branches │ └── find_spec.rb │ ├── broadcasts │ └── for_current_user_spec.rb │ ├── build │ ├── cancel_spec.rb │ ├── find_spec.rb │ ├── priority_spec.rb │ └── restart_spec.rb │ ├── build_backup │ └── find_spec.rb │ ├── build_backups │ └── all_spec.rb │ ├── build_permissions │ ├── find_for_organization_spec.rb │ ├── find_for_repo_spec.rb │ ├── update_for_organization_spec.rb │ └── update_for_repo_spec.rb │ ├── builds │ ├── find_spec.rb │ └── for_current_user_spec.rb │ ├── caches │ ├── delete_spec.rb │ └── find_spec.rb │ ├── coupons │ └── find_spec.rb │ ├── credits_calculator │ ├── calculator_spec.rb │ └── default_config_spec.rb │ ├── cron │ ├── create_spec.rb │ ├── delete_spec.rb │ ├── find_spec.rb │ └── for_branch_spec.rb │ ├── crons │ └── for_repository_spec.rb │ ├── custom_key │ └── delete_spec.rb │ ├── custom_keys │ └── create_spec.rb │ ├── email_subscription │ ├── resubscribe_spec.rb │ └── unsubscribe_spec.rb │ ├── enterprise_license │ └── find_spec.rb │ ├── env_var │ ├── delete_spec.rb │ ├── find_spec.rb │ └── update_spec.rb │ ├── env_vars │ ├── create_spec.rb │ └── for_repository_spec.rb │ ├── gdpr │ ├── export_spec.rb │ └── purge_spec.rb │ ├── insights │ ├── active_repos_spec.rb │ └── metrics_spec.rb │ ├── installation │ └── find_spec.rb │ ├── job │ ├── cancel_spec.rb │ ├── debug_spec.rb │ ├── find_spec.rb │ └── restart_spec.rb │ ├── jobs │ ├── find_for_current_user_spec.rb │ └── find_spec.rb │ ├── key_pair │ ├── create_spec.rb │ ├── delete_spec.rb │ ├── find_spec.rb │ └── update_spec.rb │ ├── lint │ └── lint_spec.rb │ ├── log │ ├── delete_spec.rb │ └── find_spec.rb │ ├── messages │ └── for_request_spec.rb │ ├── organization │ ├── find_spec.rb │ ├── suspend_spec.rb │ ├── update_billing_permission_spec.rb │ └── user_activity_spec.rb │ ├── organizations │ └── for_current_user_spec.rb │ ├── owner │ └── find_spec.rb │ ├── plans │ └── all_spec.rb │ ├── preference │ ├── find_spec.rb │ ├── for_organization_spec.rb │ └── update_spec.rb │ ├── preferences │ ├── for_organization_spec.rb │ └── for_user_spec.rb │ ├── queues │ └── stats_spec.rb │ ├── repositories │ ├── filter_spec.rb │ ├── for_current_user_spec.rb │ └── for_owner_spec.rb │ ├── repository │ ├── activate_spec.rb │ ├── deactivate_spec.rb │ ├── find_spec.rb │ ├── star_spec.rb │ ├── unstar_spec.rb │ └── update_spec.rb │ ├── request │ ├── find_spec.rb │ └── preview_spec.rb │ ├── requests │ ├── create_spec.rb │ └── find_spec.rb │ ├── scan_result │ └── find_spec.rb │ ├── scan_results │ └── all_spec.rb │ ├── ssl_key │ ├── create_spec.rb │ └── find_spec.rb │ ├── stages │ └── find_spec.rb │ ├── storage │ ├── delete_spec.rb │ ├── find_spec.rb │ └── update_spec.rb │ ├── subscription │ ├── cancel_spec.rb │ ├── invoices_spec.rb │ ├── pay_spec.rb │ ├── resubscribe_spec.rb │ ├── update_address_spec.rb │ ├── update_creditcard_spec.rb │ ├── update_payment_details_spec.rb │ └── update_plan_spec.rb │ ├── subscriptions │ ├── all_spec.rb │ └── create_spec.rb │ ├── trials │ ├── all_spec.rb │ └── create_trial_spec.rb │ ├── user │ ├── current_spec.rb │ ├── find_spec.rb │ ├── logout_spec.rb │ └── sync_spec.rb │ ├── user_setting │ ├── find_spec.rb │ └── update_spec.rb │ ├── user_settings │ └── for_repository_spec.rb │ ├── users │ └── suspend_spec.rb │ ├── v2_subscription │ ├── cancel_spec.rb │ ├── executions_spec.rb │ ├── invoices_spec.rb │ ├── pay_spec.rb │ ├── share_spec.rb │ ├── update_address_spec.rb │ ├── update_creditcard_spec.rb │ ├── update_payment_details_spec.rb │ └── update_plan_spec.rb │ └── v2_subscriptions │ ├── all_spec.rb │ └── create_spec.rb └── tmp └── .gitkeep /.dockerignore: -------------------------------------------------------------------------------- 1 | *.md 2 | .dockerignore 3 | .env 4 | .env.* 5 | .git 6 | .gitignore 7 | .travis.yml 8 | Dockerfile 9 | spec 10 | #IDEs folders 11 | .idea -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | config/travis.yml 2 | config/travis/* 3 | config/database.yml 4 | config/nginx.conf 5 | 6 | db/ 7 | 8 | tmp/ 9 | 10 | logs/ 11 | log/ 12 | 13 | .yardoc 14 | .coverage 15 | *.env 16 | .ruby-gemset 17 | 18 | #IDEs 19 | .idea 20 | 21 | .history 22 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | --colour 3 | --tty 4 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 3.2.2 2 | -------------------------------------------------------------------------------- /.tool-versions: -------------------------------------------------------------------------------- 1 | ruby 2.6.5 2 | -------------------------------------------------------------------------------- /Aptfile: -------------------------------------------------------------------------------- 1 | sysstat 2 | smem 3 | vim 4 | htop 5 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: ./script/server-buildpacks 2 | console: bundle exec ./script/console 3 | cron: bundle exec ./bin/cron 4 | -------------------------------------------------------------------------------- /bin/cron: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $stdout.sync = true 4 | 5 | $LOAD_PATH << 'lib' 6 | 7 | require 'bundler/setup' 8 | require 'travis/api/app' 9 | require 'travis/api/app/schedulers/schedule_cron_jobs' 10 | require 'marginalia' 11 | 12 | Marginalia.set('app', 'api') 13 | Marginalia.set('script', 'cron') 14 | Marginalia.set('dyno', ENV['DYNO']) 15 | 16 | Travis::Api::App.new 17 | Travis.logger.info "Starting cron jobs scheduler now" 18 | Travis::Api::App::Schedulers::ScheduleCronJobs.run 19 | -------------------------------------------------------------------------------- /bin/suspend: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require_relative './user_mgmt' 4 | 5 | unless login = ARGV.first 6 | puts "You must provide a login" 7 | exit 1 8 | end 9 | 10 | if user = User.find_by_login(login) 11 | user.update!(suspended: true, suspended_at: Time.now.utc) 12 | puts "Suspending user id=#{user.id} login=#{login}" 13 | exit 0 14 | else 15 | puts "User login=#{login} not found" 16 | exit 1 17 | end 18 | -------------------------------------------------------------------------------- /bin/unsuspend: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require_relative './user_mgmt' 4 | 5 | unless login = ARGV.first 6 | puts "You must provide a login" 7 | exit 1 8 | end 9 | 10 | if user = User.find_by_login(login) 11 | user.update!(suspended: false, suspended_at: nil) 12 | puts "Unsuspending user id=#{user.id} login=#{login}" 13 | exit 0 14 | else 15 | puts "User login=#{login} not found" 16 | exit 1 17 | end 18 | -------------------------------------------------------------------------------- /config.ru: -------------------------------------------------------------------------------- 1 | $: << 'lib' 2 | 3 | # Make sure we set that before everything 4 | ENV['RACK_ENV'] ||= ENV['RAILS_ENV'] || ENV['ENV'] 5 | ENV['RAILS_ENV'] = ENV['RACK_ENV'] 6 | 7 | $stdout.sync = true 8 | 9 | require 'travis/api/app' 10 | require 'core_ext/module/load_constants' 11 | 12 | models = Travis::Model.constants.map(&:to_s) 13 | only = [/^(ActiveRecord|ActiveModel|Travis|GH|#{models.join('|')})/] 14 | skip = ['Travis::Memory', 'GH::ResponseWrapper', 'Travis::Helpers::Legacy', 'GH::FaradayAdapter::EMSynchrony'] 15 | 16 | [Travis::Api, Travis, GH].each do |target| 17 | target.load_constants! :only => only, :skip => skip, :debug => false 18 | end 19 | 20 | run Travis::Api::App.new 21 | -------------------------------------------------------------------------------- /config/puma-config.rb: -------------------------------------------------------------------------------- 1 | root = File.expand_path('../..', __FILE__) 2 | 3 | rackup "#{root}/config.ru" 4 | 5 | tmp_dir = ENV.fetch("tmp_dir", "/tmp") 6 | bind "unix://#{tmp_dir}/nginx.socket" 7 | environment ENV['RACK_ENV'] || 'development' 8 | 9 | threads 0, 16 10 | -------------------------------------------------------------------------------- /config/ruby_config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | export RUBY_HEAP_MIN_SLOTS=800000 3 | export RUBY_GC_HEAP_INIT_SLOTS=$RUBY_HEAP_MIN_SLOTS 4 | export RUBY_GC_MALLOC_LIMIT=59000000 5 | export RUBY_HEAP_SLOTS_INCREMENT=10000 6 | export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 7 | export RUBY_HEAP_FREE_MIN=100000 8 | -------------------------------------------------------------------------------- /lib/tasks/build_update_branch.rake: -------------------------------------------------------------------------------- 1 | namespace :build do 2 | namespace :migrate do 3 | task :branch do 4 | require 'travis' 5 | Travis::Database.connect 6 | 7 | 8 | Build.select(['id', 'commit_id']).pushes.includes(:commit).find_in_batches do |builds| 9 | branches = Hash.new { |h, k| h[k] = [] } 10 | 11 | builds.each do |build| 12 | #next if build.branch 13 | branches[build.commit.branch] << build.id 14 | end 15 | 16 | branches.each do |branch, ids| 17 | Build.where(id: ids).update_all(branch: branch) 18 | end 19 | end; nil 20 | 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/tasks/populate_dont_run_if_recent_build_exists.rake: -------------------------------------------------------------------------------- 1 | # Populate :dont_run_if_recent_build_exists in Crons table 2 | # after the column has been added 3 | desc "Populate dont_run_if_recent_build_exists for all cron jobs" 4 | task :populate_dont_run_if_recent_build_exists do 5 | require "travis" 6 | require "travis/api/v3" 7 | Travis::Database.connect 8 | 9 | Travis::API::V3::Models::Cron.all.each do |cron| 10 | cron.update_attribute(:dont_run_if_recent_build_exists, cron.disable_by_build) 11 | end 12 | end 13 | 14 | task default: :populate_dont_run_if_recent_build_exists 15 | -------------------------------------------------------------------------------- /lib/travis/api/app/endpoint/accounts.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class Endpoint 5 | class Accounts < Endpoint 6 | # before { authenticate_by_mode! } 7 | 8 | get '/', scope: :private do 9 | respond_with service(:find_user_accounts, params), type: :accounts 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/app/endpoint/branches.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class Endpoint 5 | class Branches < Endpoint 6 | before { authenticate_by_mode! } 7 | 8 | get '/' do 9 | respond_with service(:find_branches, params), type: :branches 10 | end 11 | 12 | # get '/:owner_name/:name/branches' do # v1 13 | # get '/repos/:owner_name/:name/branches' do # v2 14 | # respond_with service(:branches, :find_all, params), type: :branches 15 | # end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/app/endpoint/broadcasts.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class Endpoint 5 | class Broadcasts < Endpoint 6 | get '/', scope: :private do 7 | respond_with service(:find_user_broadcasts, params), type: :broadcasts 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/app/endpoint/build_backups.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | require 'travis/api/app/responders/base' 3 | 4 | class Travis::Api::App 5 | class Endpoint 6 | class BuildBackups < Endpoint 7 | include Helpers::Accept 8 | 9 | before { authenticate_by_mode! } 10 | 11 | get '/' do 12 | prefer_follower do 13 | respond_with service(:find_build_backups, params) 14 | end 15 | end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/app/endpoint/documentation.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class Endpoint 5 | class Documentation < Endpoint 6 | set prefix: '/docs' 7 | 8 | get '/' do 9 | redirect "http://docs.travis-ci.com/api" 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/app/endpoint/error.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class Endpoint 5 | class Error < Endpoint 6 | set prefix: '/error' 7 | 8 | get '/500' do 9 | raise 'user-triggered 500' 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/app/endpoint/hooks.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class Endpoint 5 | class Hooks < Endpoint 6 | before { authenticate_by_mode! } 7 | 8 | get '/', scope: :private do 9 | respond_with service(:find_hooks, params), type: :hooks 10 | end 11 | 12 | put '/:id?', scope: :private do 13 | service = service(:update_hook, id: params[:id] || params[:hook][:id], active: params[:hook][:active]) 14 | auth_for_repo(params[:id] || params[:hook][:id], 'repository_state_update') unless Travis.config.legacy_roles 15 | disallow_migrating!(service.repo) 16 | respond_with service 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/travis/api/app/endpoint/logout.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | require 'travis/api/enqueue/services/restart_model' 3 | require 'travis/api/enqueue/services/cancel_model' 4 | require 'travis/api/app/responders/base' 5 | 6 | class Travis::Api::App 7 | class Endpoint 8 | class Logout < Endpoint 9 | before { authenticate_by_mode! } 10 | 11 | get '/' do 12 | halt 403, 'access denied' unless current_user 13 | respond_with current_user if Travis.redis.del("t:#{params[:access_token]}") == 1 14 | end 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/travis/api/app/endpoint/slow.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class Endpoint 5 | class Slow < Endpoint 6 | if ENV['SLOW_ENDPOINT_ENABLED'] == 'true' 7 | get '/' do 8 | 60.times do 9 | if Travis::RequestDeadline.enabled? 10 | Travis::RequestDeadline.check! 11 | end 12 | sleep 1 13 | end 14 | end 15 | end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/app/endpoint/uptime.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class Endpoint 5 | class Uptime < Endpoint 6 | get '/' do 7 | begin 8 | ActiveRecord::Base.connection.execute('select 1') 9 | [200, "OK"] 10 | rescue Exception => e 11 | return [500, "Error: #{e.message}"] 12 | end 13 | end 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/app/error_handling.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class ErrorHandling 5 | 6 | def self.setup 7 | return unless Travis.config.sentry.dsn 8 | 9 | Sentry.init do |config| 10 | config.dsn = Travis.config.sentry.dsn 11 | end 12 | end 13 | 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/app/extensions.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app/extensions/expose_pattern' 2 | require 'travis/api/app/extensions/scoping' 3 | require 'travis/api/app/extensions/smart_constants' 4 | require 'travis/api/app/extensions/subclass_tracker' 5 | -------------------------------------------------------------------------------- /lib/travis/api/app/extensions/expose_pattern.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | module Extensions 5 | module ExposePattern 6 | def route(verb, path, *) 7 | condition { headers('X-Endpoint' => settings.name.to_s, 'X-Pattern' => path.to_s) } 8 | super 9 | end 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/app/helpers.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | require 'travis/api/app/helpers/accept' 3 | require 'travis/api/app/helpers/current_user' 4 | require 'travis/api/app/helpers/db_follower' 5 | require 'travis/api/app/helpers/flash' 6 | require 'travis/api/app/helpers/mime_types' 7 | require 'travis/api/app/helpers/respond_with' 8 | -------------------------------------------------------------------------------- /lib/travis/api/app/helpers/current_user.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | module Helpers 5 | module CurrentUser 6 | def current_user 7 | access_token.user if signed_in? 8 | end 9 | 10 | def access_token 11 | env['travis.access_token'] 12 | end 13 | 14 | def signed_in? 15 | !!access_token 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/travis/api/app/helpers/db_follower.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | module Helpers 5 | module DbFollower 6 | def prefer_follower 7 | yield 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/app/helpers/flash.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | module Helpers 5 | module Flash 6 | def flash 7 | @flash ||= [] 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/app/helpers/mime_types.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | module Helpers 5 | module MimeTypes 6 | def html? 7 | request.accept =~ %r(text/html) 8 | end 9 | 10 | def json? 11 | request.accept =~ %r(application/json) 12 | end 13 | 14 | def xml? 15 | request.accept =~ %r(application/xml) 16 | end 17 | 18 | def png? 19 | request.accept =~ %r(image/png) 20 | end 21 | 22 | def atom? 23 | request.accept =~ %r(application/atom+xml) 24 | end 25 | end 26 | end 27 | end 28 | 29 | -------------------------------------------------------------------------------- /lib/travis/api/app/middleware/logging.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class Middleware 5 | # Makes sure we use Travis.logger everywhere. 6 | class Logging < Middleware 7 | set(:setup) { ActiveRecord::Base.logger = Travis.logger } 8 | 9 | before do 10 | env['rack.logger'] = Travis.logger 11 | env['rack.errors'] = Travis.logger.instance_variable_get(:@logdev).dev rescue nil 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/app/middleware/request_id.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | class Middleware 5 | class RequestId < Middleware 6 | after do 7 | if env['HTTP_X_REQUEST_ID'] 8 | headers['X-Request-ID'] = env['HTTP_X_REQUEST_ID'] 9 | end 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/app/responders.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/app' 2 | 3 | class Travis::Api::App 4 | module Responders 5 | autoload :Atom, 'travis/api/app/responders/atom' 6 | autoload :Base, 'travis/api/app/responders/base' 7 | autoload :Image, 'travis/api/app/responders/image' 8 | autoload :Badge, 'travis/api/app/responders/badge' 9 | autoload :Json, 'travis/api/app/responders/json' 10 | autoload :Plain, 'travis/api/app/responders/plain' 11 | autoload :Service, 'travis/api/app/responders/service' 12 | autoload :Xml, 'travis/api/app/responders/xml' 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/app/responders/badge.rb: -------------------------------------------------------------------------------- 1 | module Travis::Api::App::Responders 2 | class Badge < Image 3 | def format 4 | 'svg' 5 | end 6 | 7 | def apply 8 | set_headers 9 | if proxy_to_org? 10 | proxy_to_org 11 | elsif proxy_to_com? 12 | proxy_to_com 13 | else 14 | send_file(filename, type: :svg, last_modified: last_modified) 15 | end 16 | end 17 | 18 | def content_type 19 | "image/svg+xml" 20 | end 21 | 22 | def filename 23 | "#{root}/public/images/result/#{result}.svg" 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/formats.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module Formats 5 | def format_date(date) 6 | date && date.strftime('%Y-%m-%dT%H:%M:%SZ') 7 | end 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0.rb: -------------------------------------------------------------------------------- 1 | # V0 is an internal api that we can change at any time 2 | 3 | require 'travis/api/serialize/v0/event' 4 | require 'travis/api/serialize/v0/notification' 5 | require 'travis/api/serialize/v0/pusher' 6 | require 'travis/api/serialize/v0/worker' 7 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/event.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/serialize/v0/event/build' 2 | require 'travis/api/serialize/v0/event/job' 3 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/notification.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/serialize/v0/notification/build' 2 | require 'travis/api/serialize/v0/notification/repository' 3 | require 'travis/api/serialize/v0/notification/user' 4 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/notification/build.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Notification 6 | class Build 7 | attr_reader :build 8 | 9 | def initialize(build, options = {}) 10 | @build = build 11 | end 12 | 13 | def data 14 | { 15 | 'build' => build_data 16 | } 17 | end 18 | 19 | def build_data 20 | { 21 | 'id' => build.id 22 | } 23 | end 24 | end 25 | end 26 | end 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/notification/user.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Notification 6 | class User 7 | attr_reader :user 8 | 9 | def initialize(user, options = {}) 10 | @user = user 11 | end 12 | 13 | def data 14 | { 15 | 'user' => user_data 16 | } 17 | end 18 | 19 | def user_data 20 | { 21 | 'id' => user.id, 22 | 'login' => user.login 23 | } 24 | end 25 | end 26 | end 27 | end 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/serialize/v0/pusher/build' 2 | require 'travis/api/serialize/v0/pusher/job' 3 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher/build/canceled.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Pusher 6 | class Build 7 | class Canceled < Build 8 | end 9 | end 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher/build/created.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Pusher 6 | class Build 7 | class Created < Build 8 | end 9 | end 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher/build/finished.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Pusher 6 | class Build 7 | class Finished < Build 8 | end 9 | end 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher/build/received.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Pusher 6 | class Build 7 | class Received < Build 8 | end 9 | end 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher/build/started.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Pusher 6 | class Build 7 | class Started < Build 8 | end 9 | end 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher/job/canceled.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Pusher 6 | class Job 7 | class Canceled < Job 8 | end 9 | end 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher/job/created.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Pusher 6 | class Job 7 | class Created < Job 8 | end 9 | end 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher/job/finished.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Pusher 6 | class Job 7 | class Finished < Job 8 | end 9 | end 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher/job/received.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Pusher 6 | class Job 7 | class Received < Job 8 | end 9 | end 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/pusher/job/started.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V0 5 | module Pusher 6 | class Job 7 | class Started < Job 8 | end 9 | end 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v0/worker.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/serialize/v0/worker/job' 2 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v1.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/serialize/v1/archive' 2 | require 'travis/api/serialize/v1/http' 3 | require 'travis/api/serialize/v1/helpers' 4 | require 'travis/api/serialize/v1/webhook' 5 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v1/archive.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/serialize/v1/archive/build' 2 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v1/helpers.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/serialize/v1/helpers/legacy' 2 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v1/http.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/serialize/v1/http/branches' 2 | require 'travis/api/serialize/v1/http/build' 3 | require 'travis/api/serialize/v1/http/builds' 4 | require 'travis/api/serialize/v1/http/hooks' 5 | require 'travis/api/serialize/v1/http/job' 6 | require 'travis/api/serialize/v1/http/jobs' 7 | require 'travis/api/serialize/v1/http/repositories' 8 | require 'travis/api/serialize/v1/http/repository' 9 | require 'travis/api/serialize/v1/http/user' 10 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v1/webhook.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/serialize/v1/webhook/build' 2 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v2.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/serialize/v2/http' 2 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v2/http/account_env_var.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V2 5 | module Http 6 | class AccountEnvVar < Travis::Api::Serialize::ObjectSerializer 7 | attributes :id, :owner_id, :owner_type, :name, :value, :public, :created_at, :updated_at 8 | 9 | def serializable_hash(adapter_options) 10 | hash = super(adapter_options) 11 | hash.delete :value unless object.public? 12 | hash 13 | end 14 | end 15 | end 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v2/http/env_vars.rb: -------------------------------------------------------------------------------- 1 | class Travis::Api::Serialize::V2::Http::EnvVars < Travis::Api::Serialize::ArraySerializer 2 | end 3 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v2/http/error.rb: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lib/travis/api/serialize/v2/http/ssl_key.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Api 3 | module Serialize 4 | module V2 5 | module Http 6 | class SslKey 7 | attr_reader :key 8 | 9 | def initialize(key, options = {}) 10 | @key = key 11 | end 12 | 13 | def fingerprint 14 | PrivateKey.new(key.private_key).fingerprint 15 | end 16 | 17 | def data 18 | { 19 | 'key' => key.public_key, 20 | 'fingerprint' => fingerprint 21 | } 22 | end 23 | end 24 | end 25 | end 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/travis/api/v3/access_control/anonymous.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/v3/access_control/generic' 2 | 3 | module Travis::API::V3 4 | class AccessControl::Anonymous < AccessControl::Generic 5 | def self.new 6 | @instance ||= super 7 | end 8 | 9 | # use when Authorization header is not set 10 | auth_type(nil) 11 | 12 | def self.for_request(*) 13 | new 14 | end 15 | 16 | def admin_for(repository) 17 | raise LoginRequired 18 | end 19 | 20 | private 21 | 22 | def visible_objects(list, repository_id, factory) 23 | return factory.none unless unrestricted_api? 24 | list.where(private: false) 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/travis/api/v3/extensions/preferences.rb: -------------------------------------------------------------------------------- 1 | require 'active_support/all' 2 | 3 | module Travis::API::V3 4 | module Extensions 5 | module Preferences 6 | module ClassMethods 7 | def has_preferences(klass, column: :preferences, method_name: :preferences) 8 | define_method method_name do 9 | klass.new(self[column]).tap { |prefs| prefs.sync(self, column) } 10 | end 11 | end 12 | end 13 | 14 | def self.included(base) 15 | base.extend(ClassMethods) 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/travis/api/v3/model.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Model < ActiveRecord::Base 3 | include Extensions::BelongsTo 4 | include Extensions::Preferences 5 | 6 | self.abstract_class = true 7 | 8 | def self.===(other) 9 | super or (self == Model and other.class.module_parent == Models) 10 | end 11 | 12 | def ro_mode? 13 | return false unless Travis.config.org? && Travis.config.read_only? 14 | 15 | !Travis::Features.owner_active?(:read_only_disabled, self) 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models.rb: -------------------------------------------------------------------------------- 1 | require 'composite_primary_keys' 2 | 3 | module Travis::API::V3 4 | module Models 5 | extend ConstantResolver 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/admin_setting.rb: -------------------------------------------------------------------------------- 1 | require_relative './json_pair' 2 | 3 | module Travis::API::V3 4 | class Models::AdminSetting < Models::JsonPair 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/admin_settings.rb: -------------------------------------------------------------------------------- 1 | require_relative './json_slice' 2 | 3 | module Travis::API::V3 4 | class Models::AdminSettings < Models::JsonSlice 5 | child Models::AdminSetting 6 | attribute :api_builds_rate_limit, Integer 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/audit.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Audit < Model 3 | belongs_to :owner, polymorphic: true 4 | belongs_to :source, polymorphic: true 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/auto_refill.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::AutoRefill 3 | 4 | attr_reader :addon_id, :enabled, :threshold, :amount 5 | def initialize(attributes = {}) 6 | @addon_id = attributes.fetch('addon_id', nil) || attributes.fetch('id', nil) 7 | @enabled = attributes.key?('enabled') ? attributes.fetch('enabled') : true 8 | @threshold = attributes.key?('refill_threshold') ? attributes.fetch('refill_threshold') : 25000 9 | @amount = attributes.key?('refill_amount') ? attributes.fetch('refill_amount'): 10000 10 | end 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/beta_feature.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::BetaFeature < Model 3 | validates :name, uniqueness: true 4 | 5 | def enabled 6 | !!default_enabled 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/beta_migration_request.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::BetaMigrationRequest < Model 3 | belongs_to :owner, polymorphic: true 4 | has_many :organizations 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/billing_permissions.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::BillingPermissions 3 | def initialize(attrs = {}) 4 | @read = attrs.fetch('read') 5 | @write = attrs.fetch('write') 6 | end 7 | 8 | def read? 9 | @read 10 | end 11 | 12 | def write? 13 | @write 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/broadcast.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Broadcast < Model 3 | EXPIRY_TIME = 14.days 4 | 5 | belongs_to :recipient, polymorphic: true 6 | scope :active, -> { where('created_at >= ? AND (expired IS NULL OR expired <> ?)', EXPIRY_TIME.ago, true) } 7 | scope :inactive, -> { where('created_at < ? OR (expired = ?)', EXPIRY_TIME.ago, true) } 8 | 9 | def active? 10 | return false if expired? 11 | created_at >= EXPIRY_TIME.ago 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/build_backup.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::BuildBackup < Model 3 | attr_accessor :content 4 | 5 | belongs_to :repository 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/build_permission.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::BuildPermission 3 | attr_accessor :user, :permission, :role 4 | 5 | def initialize(attrs = {}) 6 | @user = attrs.fetch(:user) 7 | @role = attrs.fetch(:role) 8 | @permission = attrs.fetch(:permission) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/bulk_change_result.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::BulkChangeResult 3 | attr_accessor :changed, :skipped 4 | 5 | def initialize(attrs) 6 | @changed = attrs[:changed] 7 | @skipped = attrs[:skipped] 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/cache.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Cache 3 | attr_accessor :repo, :repository_id, :size, :name, :branch, :last_modified, :source, :key 4 | 5 | def self.factory(caches, repo) 6 | caches.map do |c| 7 | new(c, repo) 8 | end 9 | end 10 | 11 | def initialize(cache, repo) 12 | @repo = repo 13 | @repository_id = repo.id 14 | @size = Integer(cache.content_length) 15 | @name = cache.name.to_s.split('/').last 16 | @branch = cache.key[%r{^(.*)/(.*)/[^/]+$}, 2] 17 | @last_modified = cache.last_modified 18 | @source = cache.source 19 | @key = cache.key 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/commit.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Commit < Model 3 | belongs_to :repository 4 | has_one :request 5 | belongs_to :tag 6 | has_many :builds 7 | 8 | has_one :branch, 9 | foreign_key: [:repository_id, :name], 10 | primary_key: [:repository_id, :branch], 11 | class_name: 'Travis::API::V3::Models::Branch'.freeze 12 | 13 | def branch_name 14 | read_attribute(:branch) 15 | end 16 | 17 | def branch_name=(value) 18 | write_attribute(:branch, value) 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/coupon.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Coupon 3 | ATTRS = %w[id name percent_off amount_off valid] 4 | 5 | attr_accessor *ATTRS 6 | 7 | def initialize(attrs) 8 | ATTRS.each { |key| send("#{key}=", attrs[key]) } 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/credits_calculator_config.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::CreditsCalculatorConfig 3 | ATTRS = %w[users minutes os instance_size] 4 | 5 | attr_accessor *ATTRS 6 | 7 | def initialize(attrs) 8 | ATTRS.each { |key| send("#{key}=", attrs[key]) } 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/credits_result.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::CreditsResult 3 | ATTRS = %w[users minutes os instance_size credits price] 4 | 5 | attr_accessor *ATTRS 6 | 7 | def initialize(attrs) 8 | ATTRS.each { |key| send("#{key}=", attrs[key]) } 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/email.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Email < Model 3 | belongs_to :user 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/email_unsubscribe.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::EmailUnsubscribe < Model 3 | belongs_to :user 4 | belongs_to :repository 5 | 6 | validates :repository, uniqueness: { scope: :user } 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/installation.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Installation < Model 3 | belongs_to :owner, polymorphic: true 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/invoice.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Invoice 3 | attr_reader :id, :created_at, :status, :url, :amount_due, :cc_last_digits 4 | 5 | def initialize(attributes = {}) 6 | @id = attributes.fetch('id') 7 | @created_at = attributes.fetch('created_at') && DateTime.parse(attributes.fetch('created_at')) 8 | @status = attributes.fetch('status') 9 | @url = attributes.fetch('url') 10 | @amount_due = attributes.fetch('amount_due') 11 | @cc_last_digits = attributes.fetch('cc_last_digits') 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/jobs_stats.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::JobsStats 3 | attr_reader :started, :queued, :queue_name 4 | 5 | def initialize(attributes = {}, queue_name) 6 | @started = attributes.fetch('started') { 0 } 7 | @queued = attributes.fetch('queued') { 0 } 8 | @queue_name = queue_name 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/json_pair.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::JsonPair < Struct.new(:name, :value, :parent) 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/json_sync.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | module Models::JsonSync 3 | attr_reader :parent, :attr 4 | 5 | def sync(parent, attr) 6 | @parent, @attr = parent, attr 7 | @sync = -> do 8 | previous = @parent[@attr] || {} 9 | @parent[@attr] = previous.merge(to_h).to_json 10 | @parent.save! 11 | end 12 | end 13 | 14 | def sync_once(*args) 15 | sync(*args) 16 | sync! 17 | end 18 | 19 | def sync! 20 | @sync.call if @sync 21 | end 22 | 23 | def to_h 24 | raise NotImplementedError 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/membership.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Membership < Model 3 | belongs_to :user 4 | belongs_to :organization 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/message.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Message < Model 3 | self.inheritance_column = :none 4 | 5 | belongs_to :subject, polymorphic: true 6 | 7 | scope :ordered, -> do 8 | order(Arel.sql(%Q{ 9 | CASE 10 | WHEN level = 'alert' THEN '0' 11 | WHEN level = 'error' THEN '1' 12 | WHEN level = 'warn' THEN '2' 13 | WHEN level = 'info' THEN '3' 14 | WHEN level IS NULL THEN '4' 15 | END 16 | }.strip)) 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/organization_token.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::OrganizationToken < Model 3 | belongs_to :organization 4 | has_many :organization_token_permissions 5 | 6 | serialize :token, Travis::Model::EncryptedColumn.new 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/organization_token_permission.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::OrganizationTokenPermission < Model 3 | belongs_to :organization_token 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/owner.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | module Models::Owner 3 | private 4 | 5 | def fetch_owner(attributes) 6 | owner_class = case attributes.fetch('type') 7 | when 'User' 8 | Models::User 9 | when 'Organization' 10 | Models::Organization 11 | end 12 | owner_class.find(attributes.fetch('id')) 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/permission.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Permission < Model 3 | ROLES = %w(admin push pull) 4 | 5 | belongs_to :user 6 | belongs_to :repository 7 | 8 | class << self 9 | def by_roles(roles) 10 | roles = Array(roles).select { |role| ROLES.include?(role.to_s) } 11 | roles.empty? ? none : where(has_roles(roles)) 12 | end 13 | 14 | def has_roles(roles) 15 | roles.inject(has_role(roles.shift)) do |sql, role| 16 | sql.or(has_role(role)) 17 | end 18 | end 19 | 20 | def has_role(role) 21 | arel_table[role].eq(true) 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/plan.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Plan 3 | attr_reader :id, :name, :builds, :price, :currency, :annual 4 | 5 | def initialize(attributes = {}) 6 | @id = attributes.fetch('id') 7 | @name = attributes.fetch('name') 8 | @builds = attributes.fetch('builds') 9 | @price = attributes.fetch('price') 10 | @currency = attributes.fetch('currency') 11 | @annual = attributes.fetch('annual') 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/plan_share.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::PlanShare 3 | attr_reader :plan_id, :donor, :receiver, :shared_by, :created_at, :admin_revoked, :credits_consumed 4 | def initialize(attributes = {}) 5 | @plan_id = attributes.fetch('plan_id') 6 | @donor = attributes.fetch('donor') 7 | @receiver = attributes.fetch('receiver') 8 | @shared_by = attributes.fetch('shared_by') 9 | @created_at = attributes.fetch('created_at') 10 | @admin_revoked = attributes.fetch('admin_revoked') 11 | @credits_consumed = attributes.fetch('credits_consumed') 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/preference.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Preference < Struct.new(:name, :value, :parent) 3 | def public? 4 | true 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/pull_request.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::PullRequest < Model 3 | belongs_to :repository 4 | has_many :requests 5 | has_many :builds 6 | serialize :config 7 | serialize :payload 8 | 9 | def branch_name 10 | commit.branch_name if commit 11 | end 12 | 13 | def payload 14 | puts "[deprecated] Reading request.payload. Called from #{caller[0]}" # unless caller[0] =~ /(dirty.rb|request.rb|_spec.rb)/ 15 | super 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/remote_log.rb: -------------------------------------------------------------------------------- 1 | require 'travis/remote_log' 2 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/scanner_collection.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Travis::API::V3 4 | class Models::ScannerCollection 5 | def initialize(collection, total_count) 6 | @collection = collection 7 | @total_count = total_count 8 | end 9 | 10 | def count(*) 11 | @total_count 12 | end 13 | 14 | def limit(*) 15 | self 16 | end 17 | 18 | def offset(*) 19 | self 20 | end 21 | 22 | def map 23 | return @collection.map unless block_given? 24 | 25 | @collection.map { |x| yield x } 26 | end 27 | 28 | def to_sql 29 | "scanner_query:#{Time.now.to_i}" 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/settings.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Settings 3 | attr_reader :repository 4 | 5 | def initialize(repository) 6 | @repository = repository 7 | end 8 | 9 | def to_h 10 | repository.user_settings.to_hash 11 | end 12 | 13 | def update(settings = {}) 14 | repository.user_settings.update(settings) 15 | repository.save! 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/stage.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Stage < Model 3 | belongs_to :build 4 | has_many :jobs 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/star.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Star < Model 3 | belongs_to :user 4 | belongs_to :repository 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/storage.rb: -------------------------------------------------------------------------------- 1 | require 'redis' 2 | 3 | module Travis::API::V3 4 | class Models::Storage 5 | 6 | attr_reader :id, :value 7 | 8 | def initialize(attrs) 9 | @id = attrs.fetch(:id) 10 | @value = attrs[:value] 11 | end 12 | 13 | def public? 14 | true 15 | end 16 | 17 | def get 18 | @value = Travis.redis.get(id) || 0 19 | self 20 | end 21 | 22 | def create 23 | Travis.redis.set(id, value) 24 | self 25 | end 26 | 27 | def delete 28 | Travis.redis.del(id) 29 | @value = 0 30 | self 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/tag.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Tag < Model 3 | belongs_to :repository 4 | has_many :builds, -> { where('event_type = ?', 'push').order('builds.id DESC'.freeze) }, foreign_key: [:repository_id, :branch], primary_key: [:repository_id, :name] 5 | has_many :commits, -> { order('commits.id DESC'.freeze) }, foreign_key: [:repository_id, :branch], primary_key: [:repository_id, :name] 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/token.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Token < Model 3 | belongs_to :user 4 | validates :token, presence: true 5 | serialize :token, Travis::Model::EncryptedColumn.new(disable: true) 6 | before_validation :generate_token, on: :create 7 | 8 | protected 9 | 10 | def generate_token 11 | self.token = SecureRandom.base64(15).tr('+/=lIO0', 'pqrsxyz') 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/trial.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::Trial 3 | include Models::Owner 4 | 5 | attr_reader :id, :permissions, :owner, :created_at, :status, :builds_remaining 6 | 7 | def initialize(attributes = {}) 8 | @id = attributes.fetch('id') 9 | @permissions = Models::BillingPermissions.new(attributes.fetch('permissions')) 10 | @owner = fetch_owner(attributes.fetch('owner')) 11 | @created_at = attributes.fetch('created_at') && DateTime.parse(attributes.fetch('created_at')) 12 | @status = attributes.fetch('status') 13 | @builds_remaining = attributes.fetch('builds_remaining') 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/user_setting.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::UserSetting < Models::JsonPair 3 | 4 | def public? 5 | true 6 | end 7 | 8 | def repository_id 9 | parent && parent.id 10 | end 11 | 12 | def repository 13 | return unless repository_id 14 | V3::Models::Repository.find(repository_id) 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/user_utm_param.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::UserUtmParam < Model 3 | belongs_to :user 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/v2_addon.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::V2Addon 3 | attr_reader :id, :name, :type, :current_usage, :recurring 4 | 5 | def initialize(attrs) 6 | @id = attrs.fetch('id') 7 | @name = attrs.fetch('name') 8 | @type = attrs.fetch('type') 9 | @current_usage = attrs['current_usage'] && Models::V2AddonUsage.new(attrs['current_usage']) 10 | @recurring = attrs['recurring'] 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/models/v2_addon_usage.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Models::V2AddonUsage 3 | attr_reader :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :purchase_date, :valid_to, :active, :status 4 | 5 | def initialize(attrs) 6 | @id = attrs.fetch('id') 7 | @addon_id = attrs.fetch('addon_id') 8 | @addon_quantity = attrs.fetch('addon_quantity') 9 | @addon_usage = attrs.fetch('addon_usage') 10 | @remaining = attrs.fetch('remaining') 11 | @purchase_date = attrs.fetch('purchase_date') 12 | @valid_to = attrs.fetch('valid_to') 13 | @active = attrs.fetch('active') 14 | @status = attrs.fetch('status') 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/travis/api/v3/permissions.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | module Permissions 3 | extend ConstantResolver 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/permissions/cron.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/v3/permissions/generic' 2 | 3 | module Travis::API::V3 4 | class Permissions::Cron < Permissions::Generic 5 | def delete? 6 | return write? if Travis.config.legacy_roles 7 | 8 | authorizer.for_repo(object.branch.repository_id, 'repository_settings_delete') 9 | end 10 | 11 | def start? 12 | true 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/permissions/key_pair.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Permissions::KeyPair < Permissions::Generic 3 | def read? 4 | return repository_permissions.read? if Travis.config.legacy_roles 5 | 6 | authorizer.for_repo(object.repository.id, 'repository_settings_read') 7 | end 8 | 9 | def write? 10 | return repository_permissions.write? if Travis.config.legacy_roles 11 | 12 | authorizer.for_repo(object.repository.id, 'repository_settings_create') 13 | end 14 | 15 | private 16 | 17 | def repository_permissions 18 | @repository_permissions ||= Permissions::Repository.new(access_control, object.repository) 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/travis/api/v3/permissions/preferences.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Permissions::Preferences < Permissions::Generic 3 | def read? 4 | true 5 | end 6 | 7 | def write? 8 | true 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/permissions/ssl_key.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Permissions::SslKey < Permissions::KeyPair 3 | end 4 | end 5 | -------------------------------------------------------------------------------- /lib/travis/api/v3/permissions/subscription.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Permissions::Subscription < Permissions::Generic 3 | def read? 4 | return object.permissions.read? if Travis.config.legacy_roles || object.owner.is_a?(Travis::API::V3::Models::User) 5 | 6 | authorizer.for_org(object.owner.id, 'account_billing_view') 7 | end 8 | 9 | def write? 10 | return object.permissions.write? if Travis.config.legacy_roles || object.owner.is_a?(Travis::API::V3::Models::User) 11 | 12 | authorizer.for_org(object.owner.id, 'account_billing_update') 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/permissions/trial.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Permissions::Trial < Permissions::Generic 3 | def read? 4 | return object.permissions.read? if Travis.config.legacy_roles || object.owner.is_a?(Travis::API::V3::Models::User) 5 | 6 | authorizer.for_org(object.owner.id, 'account_billing_view') 7 | end 8 | 9 | def write? 10 | return object.permissions.write? if Travis.config.legacy_roles || object.owner.is_a?(Travis::API::V3::Models::User) 11 | 12 | authorizer.for_org(object.owner.id, 'account_billing_update') 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/permissions/user.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/v3/permissions/generic' 2 | 3 | module Travis::API::V3 4 | class Permissions::User < Permissions::Generic 5 | def sync? 6 | write? 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/permissions/user_setting.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Permissions::UserSetting < Permissions::Generic 3 | def read? 4 | return repository_permissions.read? if Travis.config.legacy_roles 5 | 6 | authorizer.for_repo(object.repository.id, 'repository_settings_read') 7 | end 8 | 9 | def write? 10 | return repository_permissions.write? if Travis.config.legacy_roles 11 | 12 | authorizer.for_repo(object.repository.id, 'repository_settings_create') 13 | end 14 | 15 | private 16 | 17 | def repository_permissions 18 | @repository_permissions ||= Permissions::Repository.new(access_control, object.repository) 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | module Queries 3 | extend ConstantResolver 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/account_env_var.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::AccountEnvVar < Query 3 | 4 | def find(params) 5 | Models::AccountEnvVar.where(owner_type: params['owner_type'], owner_id: params['owner_id']) 6 | end 7 | 8 | def create(account_env_var) 9 | raise UnprocessableEntity, "'#{params['name']}' environment variable already exists." unless Models::AccountEnvVar.where(name: params['name'], owner_id: params['owner_id'], owner_type: params['owner_type']).count.zero? 10 | account_env_var.save_account_env_var!(account_env_var) 11 | end 12 | 13 | def delete(account_env_var) 14 | account_env_var.delete(account_env_var) 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/allowance.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Allowance < Query 3 | params :login, :github_id, :provider 4 | 5 | def for_owner(owner, user_id) 6 | return true if !!Travis.config.enterprise 7 | 8 | client = BillingClient.new(user_id) 9 | client.allowance(owner_type(owner), owner.id) 10 | end 11 | 12 | private 13 | 14 | def owner_type(owner) 15 | owner.vcs_type =~ /User/ ? 'user' : 'organization' 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/beta_features.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::BetaFeatures < Query 3 | 4 | def find(user) 5 | user_beta_features = user.user_beta_features 6 | ids = user_beta_features.pluck(:beta_feature_id) 7 | if ids.empty? 8 | beta_features = Models::BetaFeature.all 9 | else 10 | beta_features = Models::BetaFeature.where('id NOT IN (?)', ids) 11 | end 12 | beta_features + user_beta_features 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/beta_migration_requests.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::BetaMigrationRequests < Query 3 | 4 | def find(user) 5 | Models::BetaMigrationRequest.where(owner_id: user.id) 6 | end 7 | 8 | def fetch_from_api(user) 9 | ComApiClient.new.find_beta_migration_requests(user) 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/branch.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Branch < Query 3 | params :name 4 | 5 | def find(repository) 6 | return repository.branch(name) if name 7 | raise WrongParams, 'missing branch.name'.freeze 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/build_backup.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::BuildBackup < RemoteQuery 3 | params :id 4 | 5 | def find 6 | raise WrongParams, 'missing build_backup.id'.freeze unless id 7 | build_backup = Models::BuildBackup.find_by_id(id) 8 | content = get(build_backup.file_name) 9 | raise EntityMissing, 'could not retrieve content'.freeze if content.nil? 10 | build_backup.content = content.force_encoding('UTF-8') if content.present? 11 | 12 | build_backup 13 | end 14 | 15 | private 16 | 17 | def main_type 18 | 'build_backup' 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/build_backups.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::BuildBackups < Query 3 | params :repository_id 4 | 5 | def all 6 | return Models::BuildBackup.where(repository_id: repository_id) if repository_id 7 | raise WrongParams, 'missing build_backups.repository_id'.freeze 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/coupons.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Coupons < Query 3 | def find(user_id, code) 4 | client = BillingClient.new(user_id) 5 | client.get_coupon(code) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/credits_calculator.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::CreditsCalculator < Query 3 | params :users, :executions 4 | 5 | def calculate(user_id) 6 | client = BillingClient.new(user_id) 7 | client.calculate_credits(params['users'], params['executions']) 8 | end 9 | 10 | def default_config(user_id) 11 | client = BillingClient.new(user_id) 12 | client.credits_calculator_default_config 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/crons.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Crons < Query 3 | def find(repository) 4 | Models::Cron.where(branch_id: repository.branches) 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/enterprise_license.rb: -------------------------------------------------------------------------------- 1 | require 'redis' 2 | 3 | module Travis::API::V3 4 | class Queries::EnterpriseLicense < Query 5 | def active_users 6 | Travis::API::V3::Models::User.where('github_oauth_token IS NOT NULL AND suspended=false') 7 | end 8 | end 9 | end -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/executions.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Executions < Query 3 | 4 | def for_owner(owner, user_id, page, per_page, from, to) 5 | client = BillingClient.new(user_id) 6 | client.executions(owner_type(owner), owner.id, page, per_page, from, to) 7 | end 8 | 9 | private 10 | 11 | def owner_type(owner) 12 | owner.vcs_type =~ /User/ ? 'user' : 'organization' 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/gdpr.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Gdpr < Query 3 | def export(user_id) 4 | GdprClient.new(user_id).export 5 | end 6 | 7 | def purge(user_id) 8 | GdprClient.new(user_id).purge 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/installation.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Installation < Query 3 | params :github_id 4 | 5 | def find 6 | Models::Installation.find_by_github_id(github_id) if github_id 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/invoices.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Invoices < Query 3 | def all(user_id) 4 | client = BillingClient.new(user_id) 5 | client.get_invoices_for_subscription(params['subscription.id']) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/messages.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Messages < Query 3 | def for_request(request) 4 | Models::Message.where(subject_type: "Request", subject_id: request.id).ordered 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/organizations.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Organizations < Query 3 | sortable_by :id, :login, :name, :github_id, :vcs_id 4 | params :role, prefix: :organization 5 | 6 | def for_member(user) 7 | orgs = Models::Organization.joins(:users).where(users: user_condition(user)) 8 | orgs = orgs.where(memberships: { role: role }) if role 9 | sort orgs 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/plans.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Plans < Query 3 | def all(user_id) 4 | client = BillingClient.new(user_id) 5 | if params['organization.id'] 6 | client.plans_for_organization(params['organization.id']) 7 | else 8 | client.plans_for_user 9 | end 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/preference.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Preference < Query 3 | params :name, :value, prefix: :preference 4 | 5 | def find(owner) 6 | owner.preferences.read(name) 7 | end 8 | 9 | def update(owner) 10 | owner.preferences.update(name, value) 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/preferences.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Preferences < Query 3 | def find(owner) 4 | owner.preferences 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/requests.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Requests < Query 3 | def find(repository) 4 | relation = repository.requests.includes(:commit) 5 | relation.includes(:yaml_config) if includes?('request.yaml_config') 6 | relation.order(id: :desc) 7 | end 8 | 9 | def count(repository, time_frame) 10 | find(repository). 11 | where(event_type: 'api'.freeze). 12 | where('created_at > ?'.freeze, time_frame.ago).count 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/scan_result.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::ScanResult < RemoteQuery 3 | params :id 4 | 5 | def find 6 | scanner_client.get_scan_result(id) 7 | end 8 | 9 | private 10 | 11 | def scanner_client 12 | @_scanner_client ||= ScannerClient.new(nil) 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/scan_results.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::ScanResults < Query 3 | params :repository_id, :offset, :limit 4 | 5 | def all 6 | # Reset the scan status on viewing the reports 7 | Repository.find(repository_id).update!(scan_failed_at: nil) 8 | 9 | page = (offset.to_i / limit.to_i) + 1 10 | scanner_client(repository_id).scan_results( 11 | page.to_s, 12 | limit 13 | ) 14 | end 15 | 16 | private 17 | 18 | def scanner_client(repository_id) 19 | @_scanner_client ||= ScannerClient.new(repository_id) 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/ssl_key.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::SslKey < Query 3 | def find(repository) 4 | repository.key 5 | end 6 | 7 | def regenerate(repository) 8 | key = repository.key || repository.create_key 9 | key.tap do |key| 10 | key.generate_keys! 11 | key.save! 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/stages.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Stages < Query 3 | 4 | def find(build) 5 | build.stages 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/trials.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::Trials < Query 3 | def all(user_id) 4 | client = BillingClient.new(user_id) 5 | client.trials 6 | end 7 | 8 | def create(user_id) 9 | client = BillingClient.new(user_id) 10 | client.create_trial(params['type'], params['owner']) 11 | client.trials 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/user_settings.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::UserSettings < Query 3 | def find(repo) 4 | repo.user_settings 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/v2_addon_usages.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::V2AddonUsages < Query 3 | def all(user_id) 4 | return unless params['subscription.id'] 5 | 6 | client = BillingClient.new(user_id) 7 | client.v2_subscription_user_usages(params['subscription.id']) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/v2_invoices.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::V2Invoices < Query 3 | def all(user_id) 4 | client = BillingClient.new(user_id) 5 | client.get_invoices_for_v2_subscription(params['subscription.id']) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/queries/v2_plans.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Queries::V2Plans < Query 3 | def all(user_id) 4 | client = BillingClient.new(user_id) 5 | if params['organization.id'] 6 | client.v2_plans_for_organization(params['organization.id']) 7 | else 8 | client.v2_plans_for_user 9 | end 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/accepted.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | module Renderer::Accepted 3 | extend self 4 | 5 | def render(payload, **options) 6 | { :@type => 'pending'.freeze, **Renderer.render_value(payload) } 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/access_token.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | module Renderer::AccessToken 3 | extend self 4 | 5 | def render(payload, **options) 6 | { :@type => 'access_token'.freeze, token: Renderer.render_value(payload) } 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/account_env_var.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::AccountEnvVar < ModelRenderer 3 | representation :standard, :id, :owner_id, :owner_type, :name, :value, :public, :created_at, :updated_at 4 | representation :minimal, :id, :owner_id, :owner_type, :name, :value, :public 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/active.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Active < CollectionRenderer 3 | type :builds 4 | collection_key :builds 5 | 6 | def representation 7 | :active 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/allowance.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Allowance < ModelRenderer 3 | representation(:minimal, :id) 4 | representation(:standard, :subscription_type, :public_repos, :private_repos, :concurrency_limit, :user_usage, :pending_user_licenses, 5 | :payment_changes_block_credit, :payment_changes_block_captcha, :credit_card_block_duration, :captcha_block_duration, :id) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/auto_refill.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::AutoRefill < ModelRenderer 3 | representation(:standard, :addon_id, :enabled, :threshold, :amount) 4 | representation(:minimal, :addon_id, :enabled, :threshold, :amount) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/beta_feature.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::BetaFeature < ModelRenderer 3 | representation(:standard, :id, :name, :description, :enabled, :feedback_url) 4 | 5 | def id 6 | return model.beta_feature_id if model.respond_to?(:beta_feature_id) 7 | model.id 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/beta_features.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::BetaFeatures < CollectionRenderer 3 | type :beta_features 4 | collection_key :beta_features 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/beta_migration_request.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::BetaMigrationRequest < ModelRenderer 3 | representation(:standard, :id, :owner_id, :owner_name, :owner_type, :accepted_at, :organizations, :organizations_logins) 4 | 5 | def organizations 6 | model.organizations.map(&:id) 7 | end 8 | 9 | def organizations_logins 10 | model.organizations.map(&:login) 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/beta_migration_requests.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::BetaMigrationRequests < CollectionRenderer 3 | type :beta_migration_requests 4 | collection_key :beta_migration_requests 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/branch.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Branch < ModelRenderer 3 | representation(:minimal, :name) 4 | representation(:standard, :name, :repository, :default_branch, :exists_on_github, :last_build) 5 | representation(:additional, :recent_builds) 6 | 7 | def recent_builds 8 | return unless include_recent_builds? 9 | access_control.visible_builds(model.builds.limit(10)) 10 | end 11 | 12 | def include_recent_builds? 13 | return true if include? 'branch.recent_builds'.freeze 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/branches.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Branches < CollectionRenderer 3 | type :branches 4 | collection_key :branches 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/broadcast.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Broadcast < ModelRenderer 3 | representation(:minimal, :id, :message, :created_at, :category, :active) 4 | representation(:standard, :id, *representations[:minimal], :recipient) 5 | 6 | def active 7 | model.active? 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/broadcasts.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Broadcasts < CollectionRenderer 3 | type :broadcasts 4 | collection_key :broadcasts 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/build_backup.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::BuildBackup < ModelRenderer 3 | representation(:minimal, :file_name, :created_at) 4 | representation(:standard, *representations[:minimal]) 5 | 6 | def self.render(model, representation = :standard, **options) 7 | return super unless options[:accept] == 'text/plain'.freeze 8 | 9 | model.content 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/build_backups.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::BuildBackups < CollectionRenderer 3 | type :build_backups 4 | collection_key :build_backups 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/build_permission.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::BuildPermission < ModelRenderer 3 | representation(:minimal, :user, :permission, :role) 4 | representation(:standard, :user, :permission, :role) 5 | 6 | def user 7 | Renderer.render_model(model.user, mode: :minimal) 8 | end 9 | 10 | def permission 11 | value = model.respond_to?(:build_permission) ? model.build_permission : model.build 12 | value.nil? ? true : value 13 | end 14 | 15 | def role 16 | model.respond_to?(:role) ? model.role : nil 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/build_permissions.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::BuildPermissions < CollectionRenderer 3 | type :build_permissions 4 | collection_key :build_permissions 5 | 6 | def render_entry(entry, **options) 7 | options[:type] = :build_permission 8 | super 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/builds.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Builds < CollectionRenderer 3 | type :builds 4 | collection_key :builds 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/bulk_change_result.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::BulkChangeResult < ModelRenderer 3 | representation(:standard, :changed,:skipped) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/cache.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Cache < ModelRenderer 3 | representation(:minimal, :repository_id, :size, :name, :branch, :last_modified) 4 | representation(:standard, *representations[:minimal], :repo) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/caches.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Caches < CollectionRenderer 3 | type :caches 4 | collection_key :caches 5 | 6 | def self.available_attributes 7 | [:branch, :match] 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/coupon.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Coupon < ModelRenderer 3 | representation(:minimal, :id, :name, :percent_off, :amount_off, :valid) 4 | representation(:standard, *representations[:minimal]) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/credits_calculator_config.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::CreditsCalculatorConfig < ModelRenderer 3 | representation(:standard, :users, :minutes, :os, :instance_size) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/credits_result.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::CreditsResult < ModelRenderer 3 | representation(:standard, :users, :minutes, :os, :instance_size, :credits, :price) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/credits_results.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::CreditsResults < CollectionRenderer 3 | type :credits_results 4 | collection_key :credits_results 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/cron.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Cron < ModelRenderer 3 | representation(:minimal, :id) 4 | representation(:standard, :id, :repository, :branch, :interval, :dont_run_if_recent_build_exists, :last_run, :next_run, :created_at, 5 | :active) 6 | 7 | def repository 8 | model.branch.repository 9 | end 10 | 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/crons.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Crons < CollectionRenderer 3 | type :crons 4 | collection_key :crons 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/custom_key.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::CustomKey < ModelRenderer 3 | representation :standard, :id, :name, :description, :public_key, :fingerprint, :added_by_login, :created_at 4 | representation :minimal, *representations[:standard] 5 | 6 | def added_by_login 7 | model.added_by.nil? ? '' : User.find(model.added_by).login 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/enterprise_license.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | module Renderer::EnterpriseLicense 3 | AVAILABLE_ATTRIBUTES = [ :license_id, :license_type, :seats, :active_users, :expiration_time ] 4 | extend self 5 | 6 | def available_attributes 7 | AVAILABLE_ATTRIBUTES 8 | end 9 | 10 | def render(license, **) 11 | { 12 | :license_id => license[:license_id], 13 | :license_type => license[:license_type], 14 | :seats => license[:seats], 15 | :active_users => license[:active_users], 16 | :expiration_time => license[:expiration_time] 17 | } 18 | end 19 | end 20 | end -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/env_var.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::EnvVar < ModelRenderer 3 | representation :standard, :id, :name, :value, :public, :branch 4 | representation :minimal, :id, :name, :public, :branch 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/env_vars.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::EnvVars < CollectionRenderer 3 | type :env_vars 4 | collection_key :env_vars 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/error.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | module Renderer::Error 3 | AVAILABLE_ATTRIBUTES = [ :error_type, :error_message, :resource_type, :permission ] 4 | extend self 5 | 6 | def available_attributes 7 | AVAILABLE_ATTRIBUTES 8 | end 9 | 10 | def render(error, **options) 11 | { 12 | :@type => 'error'.freeze, 13 | :error_type => error.type, 14 | :error_message => error.message, 15 | **Renderer.render_value(error.payload, script_name: options[:script_name]) 16 | } 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/execution.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Execution < ModelRenderer 3 | representation :minimal, :id, :os, :instance_size, :arch, :virtualization_type, :queue, :job_id, 4 | :repository_id, :owner_id, :owner_type, :plan_id, :sender_id, :credits_consumed, :started_at, 5 | :user_license_credits_consumed, :finished_at, :created_at, :updated_at, :sender_login, :repo_slug, :repo_owner_name 6 | representation :standard, *representations[:minimal] 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/execution_per_repo.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::ExecutionPerRepo < ModelRenderer 3 | representation :minimal, :repository_id, :os, :credits_consumed, :minutes_consumed, :repository 4 | representation :standard, *representations[:minimal] 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/execution_per_sender.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::ExecutionPerSender < ModelRenderer 3 | representation :minimal, :credits_consumed, :minutes_consumed, :sender_id, :sender 4 | representation :standard, *representations[:minimal] 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/executions.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Executions < CollectionRenderer 3 | type :executions 4 | collection_key :executions 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/executions_per_repo.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::ExecutionsPerRepo < CollectionRenderer 3 | type :executionsperrepo 4 | collection_key :executionsperrepo 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/executions_per_sender.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::ExecutionsPerSender < CollectionRenderer 3 | type :executionspersender 4 | collection_key :executionspersender 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/installation.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Installation < ModelRenderer 3 | representation(:minimal, :id, :github_id) 4 | representation(:standard, *representations[:minimal], :owner) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/invoice.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Invoice < ModelRenderer 3 | representation(:standard, :id, :created_at, :status, :url, :amount_due, :cc_last_digits) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/invoices.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Invoices < CollectionRenderer 3 | type :invoices 4 | collection_key :invoices 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/job_config.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::JobConfig < ModelRenderer 3 | representation(:minimal, :config) 4 | representation(:standard, *representations[:minimal]) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/jobs.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Jobs < CollectionRenderer 3 | type :jobs 4 | collection_key :jobs 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/jobs_stats.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::JobsStats < ModelRenderer 3 | representation(:standard, :started, :queued, :queue_name) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/key_pair.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::KeyPair < ModelRenderer 3 | representation :standard, :description, :public_key, :fingerprint 4 | representation :minimal, *representations[:standard] 5 | 6 | def self.available_attributes 7 | [*super, :value] 8 | end 9 | 10 | def href 11 | Renderer.href(:key_pair, 12 | :"repository.id" => model.repository_id, 13 | :"script_name" => script_name 14 | ) 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/lint.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | module Renderer::Lint 3 | extend self 4 | 5 | AVAILABLE_ATTRIBUTES = [:warnings] 6 | WARNING = /\[(alert|error|warn)\]/ 7 | 8 | def available_attributes 9 | AVAILABLE_ATTRIBUTES 10 | end 11 | 12 | def render(msgs, **) 13 | { 14 | '@type': 'lint'.freeze, 15 | warnings: warnings(msgs) 16 | } 17 | end 18 | 19 | def warnings(msgs) 20 | msgs = msgs.select { |msg| WARNING =~ msg } 21 | msgs.map { |msg| { key: [], message: msg } } 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/message.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Message < ModelRenderer 3 | representation(:minimal, :id, :level, :key, :code, :args, :src, :line) 4 | representation(:standard, *representations[:minimal]) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/messages.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Messages < CollectionRenderer 3 | type :messages 4 | collection_key :messages 5 | end 6 | end -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/organization.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/v3/renderer/owner' 2 | 3 | module Travis::API::V3 4 | class Renderer::Organization < Renderer::Owner 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/organizations.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Organizations < CollectionRenderer 3 | type :organizations 4 | collection_key :organizations 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/plan.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Plan < ModelRenderer 3 | representation(:standard, :id, :name, :builds, :price, :currency, :annual) 4 | representation(:minimal, :id, :name, :builds, :price, :currency, :annual) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/plan_share.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::PlanShare < ModelRenderer 3 | representation(:standard, :plan_id, :donor, :receiver, :shared_by, :created_at, :admin_revoked, :credits_consumed) 4 | representation(:minimal, :plan_id, :donor, :receiver, :shared_by, :created_at, :admin_revoked, :credits_consumed) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/plan_shares.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::PlanShares < CollectionRenderer 3 | type :plan_shares 4 | collection_key :plan_shares 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/plans.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Plans < CollectionRenderer 3 | type :plans 4 | collection_key :plans 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/preference.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Preference < ModelRenderer 3 | type :preference 4 | representation :standard, :name, :value 5 | representation :minimal, *representations[:standard] 6 | 7 | # TODO: I couldn't make the framework generate the URL so I'm hardcoding it :_( 8 | def href 9 | case model.parent 10 | when Models::User 11 | "/v3/preference/#{name}" 12 | when Models::Organization 13 | "/v3/org/#{model.parent.id}/preference/#{name}" 14 | # or maybe `super` ?? 15 | end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/preferences.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Preferences < CollectionRenderer 3 | type :preferences 4 | collection_key :preferences 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/proxy.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Proxy < ModelRenderer 3 | representation(:standard, :data) 4 | 5 | alias_method :data, :model 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/repositories.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Repositories < CollectionRenderer 3 | type :repositories 4 | collection_key :repositories 5 | 6 | def render 7 | authorizer.cache_repos(list.map(&:id)) 8 | super 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/request_config.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::RequestConfig < ModelRenderer 3 | representation(:minimal, :config) 4 | representation(:standard, *representations[:minimal]) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/request_preview.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::RequestPreview < ModelRenderer 3 | representation(:minimal, :raw_configs, :request_config, :job_configs, :messages, :full_messages) 4 | representation(:standard, *representations[:minimal]) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/request_raw_configuration.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::RequestRawConfiguration < ModelRenderer 3 | representation(:minimal, :config, :source, :merge_mode) 4 | representation(:standard, *representations[:minimal]) 5 | 6 | def config 7 | model.raw_config&.config 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/requests.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Requests < CollectionRenderer 3 | type :requests 4 | collection_key :requests 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/scan_results.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::ScanResults < CollectionRenderer 3 | type :scan_results 4 | collection_key :scan_results 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/ssl_key.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::SslKey < ModelRenderer 3 | type :key_pair 4 | representation :standard, :description, :public_key, :fingerprint 5 | representation :minimal, *representations[:standard] 6 | 7 | def href 8 | Renderer.href(:ssl_key, 9 | :"repository.id" => model.repository_id, 10 | :"script_name" => script_name 11 | ) 12 | end 13 | 14 | def description 15 | 'This key pair was generated by Travis CI' 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/stage.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Stage < ModelRenderer 3 | representation(:minimal, :id, :number, :name, :state, :started_at, :finished_at) 4 | representation(:standard, *representations[:minimal], :jobs) 5 | representation(:active, *representations[:standard]) 6 | 7 | hidden_representations(:active) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/stages.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Stages < CollectionRenderer 3 | type :stages 4 | collection_key :stages 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/storage.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Storage < ModelRenderer 3 | representation(:standard,:id, :value) 4 | 5 | def id 6 | model.id.split('::')&.last || id 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/subscriptions.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Subscriptions < CollectionRenderer 3 | type :subscriptions 4 | collection_key :subscriptions 5 | 6 | def fields 7 | super.tap do |fields| 8 | fields[:@permissions] = render_entry(permissions) 9 | end 10 | end 11 | 12 | private 13 | 14 | def list 15 | @list.subscriptions 16 | end 17 | 18 | def permissions 19 | @list.permissions 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/tag.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Tag < ModelRenderer 3 | representation(:minimal, :repository_id, :name, :last_build_id) 4 | representation(:standard, :repository_id, :name, :last_build_id) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/trial.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Trial < ModelRenderer 3 | representation(:standard, :id, :owner, :created_at, :status, :builds_remaining) 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/trials.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::Trials < CollectionRenderer 3 | type :trials 4 | collection_key :trials 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/user_beta_feature.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::UserBetaFeature < ModelRenderer 3 | representation :standard, :id, :name, :description, :enabled, :feedback_url 4 | 5 | type :beta_feature 6 | 7 | def id 8 | model.beta_feature.id 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/user_setting.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::UserSetting < ModelRenderer 3 | type :setting 4 | representation :standard, :name, :value 5 | representation :minimal, *representations[:standard] 6 | 7 | def href 8 | Renderer.href(:user_setting, 9 | :"repository.id" => model.repository_id, 10 | :"setting.name" => name, 11 | :"script_name" => script_name 12 | ) 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/user_settings.rb: -------------------------------------------------------------------------------- 1 | require 'travis/rollout' 2 | 3 | module Travis::API::V3 4 | class Renderer::UserSettings < CollectionRenderer 5 | type :settings 6 | collection_key :settings 7 | 8 | def render 9 | super.tap do |result| 10 | result[:settings].select!(&method(:allow?)) 11 | end 12 | end 13 | 14 | def allow?(setting) 15 | return unless setting 16 | 17 | case setting[:name] 18 | when :allow_config_imports then repo.private? 19 | else true 20 | end 21 | end 22 | 23 | def repo 24 | @repo ||= Repository.find(list.repository_id) 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/users.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/v3/renderer/owner' 2 | 3 | module Travis::API::V3 4 | class Renderer::Users < CollectionRenderer 5 | type :users 6 | collection_key :users 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/v2_addon.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::V2Addon < ModelRenderer 3 | representation(:standard, :id, :name, :type, :current_usage, :recurring) 4 | representation(:minimal, :id, :name, :type, :current_usage, :recurring) 5 | 6 | def current_usage 7 | Renderer.render_model(model.current_usage, mode: :standard) unless model.current_usage.nil? 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/v2_addon_config.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::V2AddonConfig < ModelRenderer 3 | representation(:standard, :id, :name, :price, :quantity, :type) 4 | representation(:minimal, :id, :name, :price, :quantity, :type) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/v2_addon_usage.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::V2AddonUsage < ModelRenderer 3 | representation(:standard, :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :purchase_date, :valid_to, :active, :status) 4 | representation(:minimal, :id, :addon_id, :addon_quantity, :addon_usage, :remaining, :purchase_date, :valid_to, :active, :status) 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/v2_addon_usages.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::V2AddonUsages < CollectionRenderer 3 | type :v2_addon_usages 4 | collection_key :v2_addon_usages 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/v2_plans.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::V2Plans < CollectionRenderer 3 | type :v2_plans 4 | collection_key :v2_plans 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/api/v3/renderer/v2_subscriptions.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Renderer::V2Subscriptions < CollectionRenderer 3 | type :v2_subscriptions 4 | collection_key :v2_subscriptions 5 | 6 | def fields 7 | super.tap do |fields| 8 | fields[:@permissions] = render_entry(permissions) 9 | end 10 | end 11 | 12 | private 13 | 14 | def list 15 | @list.subscriptions 16 | end 17 | 18 | def permissions 19 | @list.permissions 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /lib/travis/api/v3/result/head.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Result::Head < Result 3 | def render(*) 4 | ''.freeze 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/access_token/regenerate_token.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::AccessToken::RegenerateToken < Service 3 | params :token 4 | 5 | def run! 6 | raise LoginRequired unless access_control.logged_in? 7 | app_id = Travis::Api::App::AccessToken.find_by_token(params['token'])&.app_id || 0 8 | result query.regenerate_token(access_control.user, params['token'], app_id, expires_in: Travis::Api::App::AccessToken.auth_token_expires_in) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/access_token/remove_token.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::AccessToken::RemoveToken < Service 3 | def run! 4 | raise LoginRequired unless access_control.logged_in? 5 | app_id = Travis::Api::App::AccessToken.find_by_token(access_control.token)&.app_id 6 | query.remove_token(access_control.user, access_control.token, app_id) 7 | deleted 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/account_env_var/delete.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::AccountEnvVar::Delete < Service 3 | params :id 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | 8 | account_env_var = Travis::API::V3::Models::AccountEnvVar.find_by( 9 | id: params['id'] 10 | ) 11 | 12 | if account_env_var 13 | access_control.permissions(account_env_var).delete! 14 | query(:account_env_var).delete(account_env_var) 15 | deleted 16 | else 17 | raise NotFound, "No matching environment variable found." 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/active/for_current_user.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Builds::ForCurrentUser < Service 3 | paginate(default_limit: 100) 4 | 5 | def run! 6 | raise LoginRequired unless access_control.logged_in? 7 | result query.active_for_user(access_control.user) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/active/for_owner.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Active::ForOwner < Service 3 | def run! 4 | owner = query(:owner).find 5 | repositories = access_control.visible_repositories(owner.repositories) 6 | result query(:builds).active_from(repositories) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/allowance/for_owner.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Allowance::ForOwner < Service 3 | def run! 4 | 5 | return result BillingClient.default_allowance_response if !!Travis.config.enterprise 6 | 7 | return result BillingClient.default_allowance_response if Travis.config.org? 8 | raise LoginRequired unless access_control.logged_in? 9 | 10 | owner = query(:owner).find 11 | 12 | raise NotFound unless owner 13 | raise InsufficientAccess unless access_control.visible?(owner) 14 | 15 | result query(:allowance).for_owner(owner, access_control.user.id) 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/beta_feature/delete.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BetaFeature::Delete < Service 3 | def run! 4 | user = check_login_and_find(:user) 5 | not_found(false, :beta_feature) unless beta_feature_visible?(user) 6 | result query.delete(user) 7 | end 8 | 9 | def beta_feature_visible?(user) 10 | access_control.visible? user, :beta_feature 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/beta_feature/update.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BetaFeature::Update < Service 3 | params :id, prefix: :user 4 | params :id, :enabled, prefix: :beta_feature 5 | 6 | def run! 7 | user = check_login_and_find(:user) 8 | not_found(false, :beta_feature) unless beta_feature_visible?(user) 9 | result query.update(user) 10 | end 11 | 12 | def beta_feature_visible?(user) 13 | access_control.visible? user, :beta_feature 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/beta_features/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BetaFeatures::Find < Service 3 | def run! 4 | user = check_login_and_find(:user) 5 | not_found(false, :beta_features) unless beta_features_visible?(user) 6 | result query.find(user) 7 | end 8 | 9 | def beta_features_visible?(user) 10 | access_control.visible? user, :beta_features 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/beta_migration_requests/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BetaMigrationRequests::Find < Service 3 | params :user_login 4 | 5 | def run! 6 | raise InsufficientAccess unless access_control.full_access? 7 | user = User.find_by!(login: params['user_login']) 8 | result query.find(user) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/beta_migration_requests/proxy_find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BetaMigrationRequests::ProxyFind < Service 3 | def run! 4 | user = check_login_and_find(:user) 5 | not_found(false, :beta_migration_request) if access_control.user != user 6 | result query.fetch_from_api(user) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/branch/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Branch::Find < Service 3 | def run! 4 | result find(:branch, find(:repository)) 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/branches/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Branches::Find < Service 3 | params :exists_on_github, prefix: :branch 4 | params :name, prefix: :branch 5 | paginate 6 | 7 | def run! 8 | result query.find(find(:repository)) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/broadcasts/for_current_user.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Broadcasts::ForCurrentUser < Service 3 | params :active, prefix: :broadcast 4 | 5 | def run! 6 | raise LoginRequired unless access_control.logged_in? 7 | result query.for_user(access_control.user) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/build/cancel.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Build::Cancel < Service 3 | 4 | def run 5 | build = check_login_and_find(:build) 6 | return not_found if build.owner.ro_mode? 7 | 8 | access_control.permissions(build).cancel! 9 | 10 | query.cancel(access_control.user, build.id) 11 | accepted(build: build, state_change: :cancel) 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/build/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Build::Find < Service 3 | def run! 4 | result find 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/build/priority.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Build::Priority < Service 3 | params :cancel_all 4 | 5 | def run 6 | build = check_login_and_find(:build) 7 | query.prioritize_and_cancel(access_control.user) 8 | accepted(build: build, priority: true) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/build_backup/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BuildBackup::Find < Service 3 | params :repository_id 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | result query(:build_backup).find 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/build_backups/all.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BuildBackups::All < Service 3 | params :repository_id 4 | paginate 5 | 6 | def run! 7 | raise LoginRequired unless access_control.full_access_or_logged_in? 8 | result query(:build_backups).all 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/build_permissions/find_for_organization.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BuildPermissions::FindForOrganization < Service 3 | result_type :build_permissions 4 | 5 | def run! 6 | result query.find_for_organization(check_login_and_find(:organization)) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/build_permissions/find_for_repo.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BuildPermissions::FindForRepo < Service 3 | paginate 4 | result_type :build_permissions 5 | 6 | def run! 7 | result query.find_for_repo(check_login_and_find(:repository)) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/build_permissions/update_for_organization.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BuildPermissions::UpdateForOrganization < Service 3 | params :user_ids, :permission 4 | 5 | def run! 6 | organization = check_login_and_find(:organization) 7 | 8 | raise LoginRequired unless access_control.adminable?(organization) 9 | raise ClientError, 'user_ids must be an array' unless params['user_ids'].is_a?(Array) 10 | query.update_for_organization(organization, params['user_ids'], params['permission']) 11 | 12 | no_content 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/build_permissions/update_for_repo.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::BuildPermissions::UpdateForRepo < Service 3 | params :user_ids, :permission 4 | 5 | def run! 6 | repository = check_login_and_find(:repository) 7 | 8 | raise LoginRequired unless access_control.admin_for(repository) 9 | raise ClientError, 'user_ids must be an array' unless params['user_ids'].is_a?(Array) 10 | query.update_for_repo(repository, params['user_ids'], params['permission']) 11 | 12 | no_content 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/builds/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Builds::Find < Service 3 | params :state, :event_type, :previous_state, :created_by, prefix: :build 4 | params "branch.name" 5 | paginate 6 | 7 | def run! 8 | repository = find(:repository) 9 | unfiltered = query.find(repository) 10 | result access_control.visible_builds(unfiltered, repository.id) 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/builds/for_current_user.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Builds::ForCurrentUser < Service 3 | paginate(default_limit: 100) 4 | 5 | def run! 6 | raise LoginRequired unless access_control.logged_in? 7 | result query.for_user(access_control.user) 8 | end 9 | end 10 | end -------------------------------------------------------------------------------- /lib/travis/api/v3/services/caches/delete.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Caches::Delete < Service 3 | params :match, :branch 4 | 5 | def run! 6 | repo = check_login_and_find(:repository) 7 | access_control.permissions(repo).cache_delete! unless Travis.config.legacy_roles 8 | 9 | raise InsufficientAccess unless access_control.user.permission?(:push, repository_id: repo.id) 10 | return repo_migrated if migrated?(repo) 11 | 12 | result query.delete(repo) 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/caches/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Caches::Find < Service 3 | params :match, :branch 4 | 5 | def run! 6 | repo = check_login_and_find(:repository) 7 | access_control.permissions(repo).cache_view! unless Travis.config.legacy_roles 8 | 9 | raise InsufficientAccess unless access_control.user.permission?(:push, repository_id: repo.id) 10 | result query.find(repo) 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/coupons/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Coupons::Find < Service 3 | result_type :coupon 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | result query(:coupons).find(access_control.user.id, params['coupon.id']) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/credits_calculator/calculator.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::CreditsCalculator::Calculator < Service 3 | result_type :credits_results 4 | params :users, :executions 5 | 6 | def run! 7 | raise LoginRequired unless access_control.logged_in? 8 | 9 | result query(:credits_calculator).calculate(access_control.user.id) 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/credits_calculator/default_config.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::CreditsCalculator::DefaultConfig < Service 3 | result_type :credits_calculator_config 4 | 5 | def run! 6 | raise LoginRequired unless access_control.logged_in? 7 | 8 | result query(:credits_calculator).default_config(access_control.user.id) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/cron/delete.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Cron::Delete < Service 3 | def run! 4 | cron = check_login_and_find 5 | return repo_migrated if migrated?(cron.branch.repository) 6 | 7 | access_control.permissions(cron).delete! 8 | cron.destroy 9 | deleted 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/cron/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Cron::Find < Service 3 | #params :id 4 | 5 | def run! 6 | result find 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/cron/for_branch.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Cron::ForBranch < Service 3 | 4 | def run! 5 | repo = find(:repository) 6 | result query.find_for_branch(find(:branch, repo)) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/crons/for_repository.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Crons::ForRepository < Service 3 | paginate 4 | 5 | def run! 6 | repo = find(:repository) 7 | result query.find(repo) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/custom_key/delete.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::CustomKey::Delete < Service 3 | def run! 4 | raise LoginRequired unless access_control.full_access_or_logged_in? 5 | 6 | query(:custom_key).delete(params, access_control.user) 7 | deleted 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/custom_keys/create.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::CustomKeys::Create < Service 3 | params :owner_id, :owner_type, :name, :description, :private_key, :added_by, :public_key 4 | result_type :custom_key 5 | 6 | def run! 7 | raise LoginRequired unless access_control.full_access_or_logged_in? 8 | 9 | result query(:custom_key).create(params, access_control.user) 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/email_subscription/resubscribe.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::EmailSubscription::Resubscribe < Service 3 | def run! 4 | return run_for_org if params.include?('organization.id') 5 | 6 | repository = check_login_and_find(:repository) 7 | return repo_migrated if migrated?(repository) 8 | 9 | query.resubscribe(access_control.user, repository) 10 | no_content 11 | end 12 | 13 | def run_for_org 14 | organization = check_login_and_find(:organization) 15 | 16 | query.resubscribe_organization(access_control.user, organization) 17 | no_content 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/email_subscription/unsubscribe.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::EmailSubscription::Unsubscribe < Service 3 | def run! 4 | return run_for_org if params.include?('organization.id') 5 | 6 | repository = check_login_and_find(:repository) 7 | return repo_migrated if migrated?(repository) 8 | 9 | query.unsubscribe(access_control.user, repository) 10 | no_content 11 | end 12 | 13 | def run_for_org 14 | organization = check_login_and_find(:organization) 15 | 16 | query.unsubscribe_organization(access_control.user, organization) 17 | no_content 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/env_var/delete.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::EnvVar::Delete < Service 3 | params :id, prefix: :env_var 4 | 5 | def run! 6 | repository = check_login_and_find(:repository) 7 | return repo_migrated if migrated?(repository) 8 | 9 | env_var = find(:env_var, repository) 10 | access_control.permissions(env_var).write! 11 | app_id = Travis::Api::App::AccessToken.find_by_token(access_control.token).app_id 12 | 13 | query.delete(repository, app_id == 2) and deleted 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/env_var/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::EnvVar::Find < Service 3 | params :id, prefix: :repository 4 | params :id, prefix: :env_var 5 | 6 | def run! 7 | repository = check_login_and_find(:repository) 8 | result find(:env_var, repository) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/env_var/update.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::EnvVar::Update < Service 3 | params :name, :value, :public, :branch, prefix: :env_var 4 | 5 | def run! 6 | repository = check_login_and_find(:repository) 7 | return repo_migrated if migrated?(repository) 8 | 9 | env_var = find(:env_var, repository) 10 | access_control.permissions(env_var).write! 11 | app_id = Travis::Api::App::AccessToken.find_by_token(access_control.token).app_id 12 | 13 | result query.update(env_var, app_id == 2) 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/env_vars/create.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::EnvVars::Create < Service 3 | params :name, :value, :public, :branch, prefix: :env_var 4 | result_type :env_var 5 | 6 | def run! 7 | repository = check_login_and_find(:repository) 8 | access_control.permissions(repository).create_env_var! 9 | return repo_migrated if migrated?(repository) 10 | app_id = Travis::Api::App::AccessToken.find_by_token(access_control.token).app_id 11 | 12 | env_var = query(:env_vars).create(repository, app_id == 2) 13 | result(env_var, status: 201) 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/env_vars/for_repository.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::EnvVars::ForRepository < Service 3 | def run! 4 | repository = check_login_and_find(:repository) 5 | result find(:env_vars, repository) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/gdpr/export.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Gdpr::Export < Service 3 | def run! 4 | raise LoginRequired unless access_control.logged_in? 5 | query.export(access_control.user.id) 6 | no_content 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/gdpr/purge.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Gdpr::Purge < Service 3 | def run! 4 | raise LoginRequired unless access_control.logged_in? 5 | query.purge(access_control.user.id) 6 | no_content 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/insights/active_repos.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/v3/services/insights/insights_proxy' 2 | 3 | module Travis::API::V3 4 | class Services::Insights::ActiveRepos < Services::Insights::InsightsProxy 5 | proxy endpoint: Travis.config.insights.endpoint + '/repos/active', 6 | auth_token: Travis.config.insights.auth_token 7 | 8 | params :owner_type, :owner_id 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/insights/metrics.rb: -------------------------------------------------------------------------------- 1 | require 'travis/api/v3/services/insights/insights_proxy' 2 | 3 | module Travis::API::V3 4 | class Services::Insights::Metrics < Services::Insights::InsightsProxy 5 | proxy endpoint: Travis.config.insights.endpoint + '/metrics', 6 | auth_token: Travis.config.insights.auth_token 7 | 8 | params :owner_type, :owner_id 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/installation/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Installation::Find < Service 3 | def run! 4 | result find 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/job/cancel.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Job::Cancel < Service 3 | 4 | def run 5 | job = check_login_and_find(:job) 6 | return not_found if job.owner.ro_mode? 7 | 8 | access_control.permissions(job).cancel! 9 | query.cancel(access_control.user) 10 | accepted(job: job, state_change: :cancel) 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/job/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Job::Find < Service 3 | def run! 4 | result find 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/jobs/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Jobs::Find < Service 3 | def run! 4 | result query.find(find(:build)) 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/jobs/for_current_user.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Jobs::ForCurrentUser < Service 3 | params :active, :created_by, :state, prefix: :job 4 | paginate(default_limit: 100) 5 | 6 | def run! 7 | raise LoginRequired unless access_control.logged_in? 8 | result query.for_user(access_control.user) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/key_pair/create.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::KeyPair::Create < Service 3 | params :description, :value, prefix: :key_pair 4 | result_type :key_pair 5 | 6 | def run! 7 | repository = check_login_and_find(:repository) 8 | 9 | private_repo_feature!(repository) 10 | access_control.permissions(repository).create_key_pair! 11 | return repo_migrated if migrated?(repository) 12 | 13 | key_pair = query.create(repository) 14 | result(key_pair, status: 201) 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/key_pair/delete.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::KeyPair::Delete < Service 3 | params :description, :value, prefix: :key_pair 4 | 5 | def run! 6 | repository = check_login_and_find(:repository) 7 | 8 | private_repo_feature!(repository) 9 | return repo_migrated if migrated?(repository) 10 | 11 | key_pair = find(:key_pair, repository) 12 | access_control.permissions(repository).delete_key_pair! 13 | query.delete(repository) and deleted 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/key_pair/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::KeyPair::Find < Service 3 | def run! 4 | repository = check_login_and_find(:repository) 5 | private_repo_feature!(repository) 6 | result query.find(repository) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/key_pair/update.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::KeyPair::Update < Service 3 | params :description, :value, prefix: :key_pair 4 | result_type :key_pair 5 | 6 | def run! 7 | repository = check_login_and_find(:repository) 8 | 9 | private_repo_feature!(repository) 10 | return repo_migrated if migrated?(repository) 11 | 12 | key_pair = find(:key_pair, repository) 13 | access_control.permissions(key_pair).write! 14 | 15 | key_pair = query.update(key_pair) 16 | result(key_pair, status: 200) 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/lint/lint.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Lint::Lint < Service 3 | params 'content' 4 | 5 | def run! 6 | request_body.rewind 7 | content = params['content'.freeze] || request_body.read 8 | result query.lint(content) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/log/delete.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Log::Delete < Service 3 | def run! 4 | job = check_login_and_find(:job) 5 | access_control.permissions(job).delete_log! 6 | result query.delete(access_control.user, job) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/messages/for_request.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Messages::ForRequest < Service 3 | paginate 4 | 5 | def run! 6 | raise NotFound unless request = query(:request).find 7 | result query.for_request(request) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/organization/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Organization::Find < Service 3 | def run! 4 | result find 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/organization/sync.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travis-ci/travis-api/12ee6c9a1e29360a232f8b64662859b01e98d1d4/lib/travis/api/v3/services/organization/sync.rb -------------------------------------------------------------------------------- /lib/travis/api/v3/services/organization/update_billing_permission.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Organization::UpdateBillingPermission < Service 3 | params :billing_admin_only 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.update_billing_permission(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end -------------------------------------------------------------------------------- /lib/travis/api/v3/services/organizations/for_current_user.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Organizations::ForCurrentUser < Service 3 | params :role, prefix: :organization 4 | paginate(default_limit: 100) 5 | 6 | def run! 7 | raise LoginRequired unless access_control.logged_in? 8 | result query.for_member(access_control.user) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/owner/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Owner::Find < Service 3 | def result_type 4 | @result_type ||= super 5 | end 6 | 7 | def run! 8 | owner = find 9 | @result_type = type_for(owner) 10 | result owner 11 | end 12 | 13 | def type_for(owner) 14 | case owner 15 | when Models::User then :user 16 | when Models::Organization then :organization 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/plans/all.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Plans::All < Service 3 | params :organization_id 4 | def run! 5 | raise LoginRequired unless access_control.full_access_or_logged_in? 6 | result query(:plans).all(access_control.user.id) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/preference/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Preference::Find < Service 3 | def run! 4 | user = access_control.user or raise LoginRequired 5 | result query.find(user) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/preference/for_organization.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Preference::ForOrganization < Service 3 | def run! 4 | organization = check_login_and_find(:organization) 5 | result find(:preference, organization) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/preference/update.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Preference::Update < Service 3 | params :value, prefix: :preference 4 | 5 | def run! 6 | owner = access_control.user or raise LoginRequired 7 | owner = find(:organization) if params['organization.id'] 8 | result query.update(owner) if access_control.adminable?(owner) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/preferences/for_organization.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Preferences::ForOrganization < Service 3 | def run! 4 | organization = check_login_and_find(:organization) 5 | prefs = find(:preferences, organization) 6 | result prefs 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/preferences/for_user.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Preferences::ForUser < Service 3 | def run! 4 | prefs = check_login_and_find(:preferences, access_control.user) 5 | result prefs 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/queues/stats.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Queues::Stats < Service 3 | result_type :jobs_stats 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access? 7 | result query(:jobs).stats_by_queue(params['queue.name']) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/repositories/for_current_user.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Repositories::ForCurrentUser < Service 3 | params :active, :private, :starred, :name_filter, :slug_filter, 4 | :managed_by_installation, :active_on_org, prefix: :repository 5 | paginate(default_limit: 100) 6 | 7 | def run! 8 | raise LoginRequired unless access_control.logged_in? 9 | result query.for_member(access_control.user) 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/repositories/for_owner.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Repositories::ForOwner < Service 3 | params :active, :private, :starred, :name_filter, :slug_filter, 4 | :managed_by_installation, :active_on_org, prefix: :repository 5 | paginate(default_limit: 100) 6 | 7 | def run! 8 | unfiltered = query.for_owner(find(:owner), user: access_control.user) 9 | result access_control.visible_repositories(unfiltered) 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/repository/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Repository::Find < Service 3 | params :server_type 4 | 5 | def run! 6 | result find 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/repository/settings.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travis-ci/travis-api/12ee6c9a1e29360a232f8b64662859b01e98d1d4/lib/travis/api/v3/services/repository/settings.rb -------------------------------------------------------------------------------- /lib/travis/api/v3/services/repository/star.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Repository::Star < Service 3 | def run! 4 | repository = check_login_and_find(:repository) 5 | check_access(repository) 6 | return repo_migrated if migrated?(repository) 7 | 8 | current_user = access_control.user 9 | result query.star(current_user) 10 | end 11 | 12 | def check_access(repository) 13 | access_control.permissions(repository).star! 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/repository/unstar.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Repository::Unstar < Service 3 | def run! 4 | repository = check_login_and_find(:repository) 5 | check_access(repository) 6 | return repo_migrated if migrated?(repository) 7 | 8 | current_user = access_control.user 9 | result query.unstar(current_user) 10 | end 11 | 12 | def check_access(repository) 13 | access_control.permissions(repository).unstar! 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/repository/update.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Repository::Update < Service 3 | params :com_id, prefix: :repository 4 | 5 | def run! 6 | repository = check_login_and_find(:repository) 7 | raise InsufficientAccess unless access_control.full_access? 8 | return repo_migrated if migrated?(repository) 9 | 10 | query.update(attrs) 11 | result repository 12 | end 13 | 14 | def attrs 15 | { 16 | com_id: params['com_id'], 17 | active: !!params['active'] 18 | } 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/repository_vcs/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::RepositoryVcs::Find < Service 3 | def run! 4 | result find, type: :repository 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/request/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Request::Find < Service 3 | 4 | def run! 5 | result find 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/requests/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Requests::Find < Service 3 | paginate 4 | def run! 5 | repository = find(:repository) 6 | unfiltered = query.find(repository) 7 | result access_control.visible_requests(unfiltered, repository.id) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/scan_result/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::ScanResult::Find < Service 3 | params :id 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | scan_result = query(:scan_result).find 8 | 9 | repository = Travis::API::V3::Models::Repository.find(scan_result.repository_id) 10 | check_access(repository) 11 | 12 | result scan_result 13 | end 14 | 15 | def check_access(repository) 16 | access_control.permissions(repository).check_scan_results! 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/scan_results/all.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::ScanResults::All < Service 3 | params :repository_id 4 | paginate 5 | 6 | def run! 7 | raise LoginRequired unless access_control.full_access_or_logged_in? 8 | 9 | repository = Travis::API::V3::Models::Repository.find(params['repository_id']) 10 | check_access(repository) 11 | 12 | result query(:scan_results).all 13 | end 14 | 15 | def check_access(repository) 16 | access_control.permissions(repository).check_scan_results! 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/ssl_key/create.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::SslKey::Create < Service 3 | result_type :ssl_key 4 | 5 | def run! 6 | repository = check_login_and_find(:repository) 7 | access_control.permissions(repository).create_key_pair! 8 | return repo_migrated if migrated?(repository) 9 | 10 | ssl_key = query.regenerate(repository) 11 | result(ssl_key, status: 201) 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/ssl_key/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::SslKey::Find < Service 3 | def run! 4 | repository = check_login_and_find(:repository) 5 | result(query.find(repository) || not_found(false, :key_pair)) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/stages/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Stages::Find < Service 3 | def run! 4 | result query.find(find(:build)) 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/storage/delete.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Storage::Delete < Service 3 | def run! 4 | raise LoginRequired unless access_control.full_access_or_logged_in? 5 | 6 | params['user.id'] = access_control.user&.id 7 | result query.delete 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/storage/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Storage::Find < Service 3 | def run! 4 | raise LoginRequired unless access_control.full_access_or_logged_in? 5 | 6 | params['user.id'] = access_control.user&.id 7 | result query.find 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/storage/update.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Storage::Update < Service 3 | params :id, :value 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | 8 | params['user.id'] = access_control.user&.id 9 | result query.update 10 | end 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscription/cancel.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscription::Cancel < Service 3 | params :reason, :reason_details 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.cancel(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscription/invoices.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscription::Invoices < Service 3 | result_type :invoices 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | result query(:invoices).all(access_control.user.id) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscription/pause.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscription::Pause < Service 3 | params :reason, :reason_details 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.pause(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscription/pay.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscription::Pay < Service 3 | result_type :subscription 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | result query.pay(access_control.user.id), status: 200 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscription/resubscribe.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscription::Resubscribe < Service 3 | def run! 4 | raise LoginRequired unless access_control.full_access_or_logged_in? 5 | result query.resubscribe(access_control.user.id), status: 201 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscription/update_address.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscription::UpdateAddress < Service 3 | params :first_name, :last_name, :company, :address, :address2, :city, :country, :state, :vat_id, :zip_code, :billing_email, :has_local_registration 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.update_address(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscription/update_creditcard.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscription::UpdateCreditcard < Service 3 | params :token 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.update_creditcard(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscription/update_payment_details.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscription::UpdatePaymentDetails < Service 3 | params :captcha_token, :token, :first_name, :last_name, :company, :address, :address2, :city, :country, :state, :vat_id, :zip_code, :billing_email, :has_local_registration 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.update_payment_details(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscription/update_plan.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscription::UpdatePlan < Service 3 | params :plan 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.update_plan(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscriptions/all.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscriptions::All < Service 3 | def run! 4 | raise LoginRequired unless access_control.full_access_or_logged_in? 5 | result query(:subscriptions).all(access_control.user.id) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/subscriptions/create.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Subscriptions::Create < Service 3 | result_type :subscription 4 | params :plan, :coupon, :organization_id, :client_secret 5 | params :first_name, :last_name, :company, :address, :address2, :city, :country, :state, :vat_id, :zip_code, :billing_email, :has_local_registration, prefix: :billing_info 6 | params :token, prefix: :credit_card_info 7 | 8 | def run! 9 | raise LoginRequired unless access_control.full_access_or_logged_in? 10 | result query(:subscriptions).create(access_control.user.id), status: 201 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/trials/all.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Trials::All < Service 3 | def run! 4 | raise LoginRequired unless access_control.full_access_or_logged_in? 5 | result query(:trials).all(access_control.user.id) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/trials/create.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Trials::Create < Service 3 | params :owner, :type 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | result query(:trials).create(access_control.user.id), status: 202 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/user/current.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::User::Current < Service 3 | def run! 4 | raise LoginRequired unless access_control.logged_in? 5 | result(access_control.user || not_found(false)) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/user/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::User::Find < Service 3 | def run! 4 | result find 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/user/logout.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::User::Logout < Service 3 | def run! 4 | raise LoginRequired unless access_control.logged_in? 5 | result(access_control.user) if Travis.redis.del("t:#{access_control.token}") == 1 6 | end 7 | end 8 | end -------------------------------------------------------------------------------- /lib/travis/api/v3/services/user/sync.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::User::Sync < Service 3 | 4 | def run! 5 | user = check_login_and_find(:user) 6 | return not_found if user.ro_mode? 7 | 8 | access_control.permissions(user).sync! 9 | 10 | result query.sync(user) 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/user/update.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::User::Update < Service 3 | result_type :user 4 | params :utm_params 5 | 6 | def run! 7 | raise LoginRequired unless access_control.logged_in? && access_control.user 8 | raise WrongParams if utm_data.empty? 9 | 10 | Models::UserUtmParam.new( 11 | utm_data: utm_data, 12 | user: access_control.user 13 | ).save 14 | 15 | result(access_control.user) 16 | end 17 | 18 | private 19 | 20 | def utm_data 21 | json = params["utm_params"] 22 | return {} unless json.is_a?(Hash) 23 | json.filter { |key| key.start_with?("utm_") } 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/user_setting/find.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::UserSetting::Find < Service 3 | def run! 4 | repository = check_login_and_find(:repository) 5 | 6 | access_control.permissions(repository).settings_read! 7 | result find(:user_setting, repository) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/user_setting/update.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::UserSetting::Update < Service 3 | type :setting 4 | params :value, prefix: :setting 5 | 6 | def run! 7 | repository = check_login_and_find(:repository) 8 | return repo_migrated if migrated?(repository) 9 | 10 | user_setting = query.find(repository) 11 | access_control.permissions(user_setting).write! if user_setting 12 | app_id = Travis::Api::App::AccessToken.find_by_token(access_control.token).app_id 13 | 14 | user_setting = query.update(repository, access_control.user, app_id == 2) 15 | result user_setting 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/user_settings/for_repository.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::UserSettings::ForRepository < Service 3 | def run! 4 | repo = check_login_and_find(:repository) 5 | 6 | access_control.permissions(repo).settings_read! 7 | result query.find(repo) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/users/suspend.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Users::Suspend < Service 3 | params :user_ids, :vcs_type, :vcs_ids 4 | result_type :bulk_change_result 5 | 6 | ALLOWED_CLASSES = %w[Travis::API::V3::AccessControl::Internal] 7 | 8 | def run! 9 | raise LoginRequired unless ALLOWED_CLASSES.include? access_control.class.name 10 | raise WrongParams unless valid_params? 11 | 12 | result query(:users).suspend(true) 13 | end 14 | 15 | private def valid_params? 16 | params.include?('user_ids') || ( params.include?('vcs_type') && params.include?('vcs_ids') ) 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/users/unsuspend.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::Users::Unsuspend < Service 3 | params :user_ids, :vcs_type, :vcs_ids 4 | result_type :bulk_change_result 5 | 6 | def run! 7 | raise LoginRequired unless access_control.class.name == 'Travis::API::V3::AccessControl::Internal' 8 | raise WrongParams unless valid_params? 9 | 10 | result query(:users).suspend(false) 11 | end 12 | 13 | private def valid_params? 14 | params.include?('user_ids') || ( params.include?('vcs_type') && params.include?('vcs_ids') ) 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_plans/all.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Plans::All < Service 3 | params :organization_id 4 | def run! 5 | raise LoginRequired unless access_control.full_access_or_logged_in? 6 | 7 | begin 8 | unless Travis::API::V3::Authorizer::new(access_control.user.id).for_org(params['organization_id'], 'account_plan_view') 9 | raise InsufficientAccess 10 | end 11 | rescue AuthorizerError 12 | #nop 13 | end if !Travis.config.legacy_roles && params.include?('organization_id') 14 | 15 | result query(:v2_plans).all(access_control.user.id) 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/auto_refill.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::AutoRefill < Service 3 | result_type :auto_refill 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | result query.get_auto_refill(access_control.user.id, params['subscription.id']), status: 200 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/buy_addon.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::BuyAddon < Service 3 | params :plan 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.buy_addon(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/cancel.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::Cancel < Service 3 | params :reason, :reason_details 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.cancel(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/changetofree_plan.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::Changetofree < Service 3 | params :plan 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.changetofree(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/invoices.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::Invoices < Service 3 | result_type :invoices 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | result query(:v2_invoices).all(access_control.user.id) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/pause.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::Pause < Service 3 | params :reason, :reason_details 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.pause(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/pay.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::Pay < Service 3 | result_type :v2_subscription 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | result query.pay(access_control.user.id), status: 200 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/share.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::Share < Service 3 | params :receiver_id, :receiver 4 | def run! 5 | raise LoginRequired unless access_control.full_access_or_logged_in? 6 | if @env['REQUEST_METHOD'] == 'DELETE' then 7 | query.delete_share(access_control.user.id, params['receiver_id']) 8 | else 9 | query.share(access_control.user.id, params['receiver_id']) 10 | end 11 | no_content 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/toggle_auto_refill.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::ToggleAutoRefill < Service 3 | params :enabled 4 | def run! 5 | raise LoginRequired unless access_control.full_access_or_logged_in? 6 | query.toggle_auto_refill(access_control.user.id, params['subscription.id']) 7 | no_content 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/update_address.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::UpdateAddress < Service 3 | params :first_name, :last_name, :company, :address, :address2, :city, :country, :state, :vat_id, :zip_code, :billing_email, :has_local_registration 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.update_address(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/update_auto_refill.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::UpdateAutoRefill < Service 3 | params :addon_id, :threshold, :amount 4 | def run! 5 | raise LoginRequired unless access_control.full_access_or_logged_in? 6 | query.update_auto_refill(access_control.user.id, params['addon_id']) 7 | no_content 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/update_creditcard.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::UpdateCreditcard < Service 3 | params :token, :fingerprint 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.update_creditcard(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/update_payment_details.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::UpdatePaymentDetails < Service 3 | params :captcha_token, :token, :fingerprint, :first_name, :last_name, :company, :address, :address2, :city, :country, :state, :vat_id, :zip_code, :billing_email, :has_local_registration 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.update_payment_details(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/update_plan.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::UpdatePlan < Service 3 | params :plan, :coupon 4 | 5 | def run! 6 | raise LoginRequired unless access_control.full_access_or_logged_in? 7 | query.update_plan(access_control.user.id) 8 | no_content 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscription/user_usages.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscription::UserUsages < Service 3 | params :subscription_id 4 | result_type :v2_addon_usages 5 | 6 | def run! 7 | raise LoginRequired unless access_control.full_access_or_logged_in? 8 | result query(:v2_addon_usages).all(access_control.user.id) 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscriptions/all.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscriptions::All < Service 3 | def run! 4 | raise LoginRequired unless access_control.full_access_or_logged_in? 5 | result query(:v2_subscriptions).all(access_control.user.id) 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/travis/api/v3/services/v2_subscriptions/create.rb: -------------------------------------------------------------------------------- 1 | module Travis::API::V3 2 | class Services::V2Subscriptions::Create < Service 3 | result_type :v2_subscription 4 | params :plan, :coupon, :organization_id, :client_secret, :v1_subscription_id 5 | params :first_name, :last_name, :company, :address, :address2, :city, :country, :state, :vat_id, :zip_code, :billing_email, :has_local_registration, prefix: :billing_info 6 | params :token, :fingerprint, prefix: :credit_card_info 7 | 8 | def run! 9 | raise LoginRequired unless access_control.full_access_or_logged_in? 10 | result query(:v2_subscriptions).create(access_control.user.id), status: 201 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/errors.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | class RepositoryNotFoundError < StandardError 3 | def initialize(params) 4 | details = '' 5 | 6 | if id = params[:repository_id] || params[:id] 7 | details = "with id=#{params[:repository_id] || params[:id]} " 8 | elsif params[:github_id] 9 | details = "with github_id=#{params[:github_id]} " 10 | elsif params.key?(:slug) 11 | details = "with slug=#{params[:slug]} " 12 | elsif params.key?(:name) && params.key?(:owner_name) 13 | details = "with slug=#{params[:name]}/#{params[:owner_name]} " 14 | end 15 | 16 | 17 | super("Repository #{details}could not be found") 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/travis/github/services.rb: -------------------------------------------------------------------------------- 1 | require 'travis/github/services/set_hook' 2 | require 'travis/github/services/set_key' 3 | 4 | module Travis 5 | module Github 6 | module Services 7 | class << self 8 | def register 9 | constants(false).each { |name| const_get(name) } 10 | end 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/marginalia.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'marginalia' 4 | require 'active_record/connection_adapters/postgresql_adapter' 5 | 6 | module Travis 7 | class Marginalia 8 | class << self 9 | def setup 10 | ::Marginalia.install 11 | end 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/travis/model/branch.rb: -------------------------------------------------------------------------------- 1 | require 'travis/model' 2 | 3 | class Branch < Travis::Model 4 | self.table_name = 'branches' 5 | include Travis::ScopeAccess 6 | 7 | belongs_to :repository 8 | belongs_to :last_build, class_name: 'Build' 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/model/build/config/group.rb: -------------------------------------------------------------------------------- 1 | class Build 2 | class Config 3 | class Group 4 | DEFAULT_GROUP = 'stable' 5 | 6 | attr_reader :config 7 | 8 | def initialize(config, *) 9 | @config = config 10 | end 11 | 12 | def run 13 | return config if config.key?(:group) || config.key?('group') 14 | config.merge(group: DEFAULT_GROUP) 15 | end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/travis/model/build/config/os.rb: -------------------------------------------------------------------------------- 1 | class Build 2 | class Config 3 | class OS 4 | OS_LANGUAGE_MAP = { 5 | 'objective-c' => 'osx', 6 | } 7 | DEFAULT_OS = 'linux' 8 | 9 | attr_reader :config 10 | 11 | def initialize(config, _) 12 | @config = config 13 | end 14 | 15 | def run 16 | return config if config.key?(:os) || config.key?('os') 17 | config.merge(os: os_for_language) 18 | end 19 | 20 | private 21 | 22 | def os_for_language 23 | OS_LANGUAGE_MAP.fetch(config[:language], DEFAULT_OS) 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/travis/model/build/config/yaml.rb: -------------------------------------------------------------------------------- 1 | class Build 2 | class Config 3 | class Yaml < Struct.new(:config, :options) 4 | def run 5 | normalize(config) 6 | end 7 | 8 | def normalize(hash) 9 | Hash[hash.map { |key, value| [key == true ? :on : key, value] }] 10 | end 11 | end 12 | end 13 | end 14 | 15 | -------------------------------------------------------------------------------- /lib/travis/model/build/metrics.rb: -------------------------------------------------------------------------------- 1 | require 'travis/model/build' 2 | class Build 3 | module Metrics 4 | def start(data = {}) 5 | super 6 | meter 'travis.builds.start.delay', started_at - request.created_at 7 | end 8 | 9 | private 10 | 11 | def meter(name, time) 12 | Metriks.timer(name).update(time) 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/model/build_backup.rb: -------------------------------------------------------------------------------- 1 | require 'travis/model' 2 | 3 | class BuildBackup < Travis::Model 4 | self.table_name = 'build_backups' 5 | include Travis::ScopeAccess 6 | 7 | belongs_to :repository 8 | validates :repository_id, presence: true 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/model/email.rb: -------------------------------------------------------------------------------- 1 | require 'travis/model' 2 | 3 | class Email < Travis::Model 4 | self.table_name = 'emails' 5 | belongs_to :user 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/model/env_helpers.rb: -------------------------------------------------------------------------------- 1 | module Travis::Model::EnvHelpers 2 | def obfuscate_env(vars) 3 | vars = [vars] unless vars.is_a?(Array) 4 | vars.compact.map do |var| 5 | repository.key.secure.decrypt(var) do |decrypted| 6 | next unless decrypted 7 | if decrypted.include?('=') 8 | "#{decrypted.to_s.split('=').first}=[secure]" 9 | else 10 | '[secure]' 11 | end 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/model/membership.rb: -------------------------------------------------------------------------------- 1 | require 'travis/model' 2 | 3 | class Membership < Travis::Model 4 | self.table_name = 'memberships' 5 | belongs_to :user 6 | belongs_to :organization 7 | end 8 | 9 | -------------------------------------------------------------------------------- /lib/travis/model/owner_group.rb: -------------------------------------------------------------------------------- 1 | require 'gh' 2 | require 'travis/model' 3 | 4 | class OwnerGroup < Travis::Model 5 | self.table_name = 'owner_groups' 6 | belongs_to :owner, polymorphic: true 7 | end 8 | -------------------------------------------------------------------------------- /lib/travis/model/pull_request.rb: -------------------------------------------------------------------------------- 1 | class PullRequest < ActiveRecord::Base 2 | self.table_name = 'pull_requests' 3 | belongs_to :repository 4 | has_many :requests 5 | has_many :builds 6 | end 7 | -------------------------------------------------------------------------------- /lib/travis/model/remote_log.rb: -------------------------------------------------------------------------------- 1 | require 'travis/remote_log' 2 | -------------------------------------------------------------------------------- /lib/travis/model/url.rb: -------------------------------------------------------------------------------- 1 | require 'digest/sha1' 2 | require 'travis/model' 3 | 4 | class Url < Travis::Model 5 | validates :url, :presence => true, :uniqueness => true 6 | validates :code, :presence => true, :uniqueness => true 7 | 8 | before_validation :set_code, :on => :create 9 | 10 | def self.shorten(url) 11 | find_or_create_by(url: url) 12 | end 13 | 14 | def short_url 15 | ["http://#{Travis.config.shorten_host}", code].join('/') 16 | end 17 | 18 | private 19 | 20 | def set_code 21 | self.code = Digest::SHA1.hexdigest(url)[0..9] 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/travis/notification/publisher.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Notification 3 | module Publisher 4 | require 'travis/notification/publisher/log' 5 | require 'travis/notification/publisher/redis' 6 | require 'travis/notification/publisher/memory' 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /lib/travis/notification/publisher/memory.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Notification 3 | module Publisher 4 | class Memory 5 | def publish(event) 6 | events << event 7 | end 8 | 9 | def events 10 | @events ||= [] 11 | end 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/remote_vcs/response_error.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | module Travis 4 | class RemoteVCS 5 | class ResponseError < StandardError 6 | def initialize(message = 'VCS response error') 7 | super message 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /lib/travis/services/delete_caches.rb: -------------------------------------------------------------------------------- 1 | require 'travis/services/base' 2 | 3 | module Travis 4 | module Services 5 | class DeleteCaches < Base 6 | register :delete_caches 7 | 8 | def run 9 | raise Travis::AuthorizationDenied unless authorized? 10 | 11 | caches = run_service(:find_caches, params) 12 | caches.each { |c| c.destroy } 13 | caches 14 | end 15 | 16 | private 17 | 18 | def authorized? 19 | current_user && repo && current_user.permission?(:push, repository_id: repo.id) 20 | end 21 | 22 | def repo 23 | @repo ||= run_service(:find_repo, params) 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/travis/services/find_build_backups.rb: -------------------------------------------------------------------------------- 1 | require 'travis/services/base' 2 | 3 | module Travis 4 | module Services 5 | class FindBuildBackups < Base 6 | register :find_build_backups 7 | 8 | scope_access! 9 | 10 | def run 11 | result 12 | end 13 | 14 | private 15 | 16 | def result 17 | @result ||= scope(:build_backup).where(repository_id: params[:repository_id]) 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /lib/travis/services/find_hooks.rb: -------------------------------------------------------------------------------- 1 | require 'travis/services/base' 2 | 3 | module Travis 4 | module Services 5 | class FindHooks < Base 6 | register :find_hooks 7 | 8 | def run 9 | current_user.service_hooks(params) 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/services/find_repo.rb: -------------------------------------------------------------------------------- 1 | require 'travis/services/base' 2 | 3 | module Travis 4 | module Services 5 | class FindRepo < Base 6 | register :find_repo 7 | 8 | scope_access! 9 | 10 | def run(options = {}) 11 | result 12 | end 13 | 14 | def updated_at 15 | result.try(:updated_at) 16 | end 17 | 18 | private 19 | 20 | def result 21 | @result ||= scope(:repository).by_params(params).to_a.first 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/travis/services/find_repo_key.rb: -------------------------------------------------------------------------------- 1 | require 'travis/services/base' 2 | 3 | module Travis 4 | module Services 5 | class FindRepoKey < FindRepo 6 | register :find_repo_key 7 | 8 | scope_access! 9 | 10 | def run(options = {}) 11 | result 12 | end 13 | 14 | def updated_at 15 | result.try(:updated_at) 16 | end 17 | 18 | private 19 | 20 | def result 21 | @result ||= (repo = super) ? repo.key : nil 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /lib/travis/services/find_request.rb: -------------------------------------------------------------------------------- 1 | module Travis 2 | module Services 3 | class FindRequest < Base 4 | register :find_request 5 | 6 | scope_access! 7 | 8 | def run(options = {}) 9 | result 10 | end 11 | 12 | def final? 13 | true 14 | end 15 | 16 | def updated_at 17 | result.updated_at if result.respond_to?(:updated_at) 18 | end 19 | 20 | private 21 | 22 | def result 23 | @result ||= scope(:request).find_by_id(params[:id]) 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/travis/services/find_user_broadcasts.rb: -------------------------------------------------------------------------------- 1 | require 'travis/services/base' 2 | 3 | module Travis 4 | module Services 5 | class FindUserBroadcasts < Base 6 | register :find_user_broadcasts 7 | 8 | def run 9 | Broadcast.by_user(current_user) 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/travis/services/find_user_permissions.rb: -------------------------------------------------------------------------------- 1 | require 'travis/services/base' 2 | 3 | module Travis 4 | module Services 5 | class FindUserPermissions < Base 6 | register :find_user_permissions 7 | 8 | def run 9 | scope = current_user.permissions 10 | scope = scope.by_roles(params[:roles].to_s.split(',')) if params[:roles] 11 | scope 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/travis/services/helpers.rb: -------------------------------------------------------------------------------- 1 | require 'travis/services/registry' 2 | 3 | module Travis 4 | module Services 5 | module Helpers 6 | def run_service(key, *args) 7 | service(key, *args).run 8 | end 9 | 10 | def service(key, *args) 11 | params = args.last.is_a?(Hash) ? args.pop : {} 12 | user = args.last 13 | user ||= current_user if respond_to?(:current_user) 14 | Travis.services[key].new(user, params) 15 | end 16 | end 17 | end 18 | 19 | extend Services::Helpers 20 | end 21 | -------------------------------------------------------------------------------- /lib/travis/testing.rb: -------------------------------------------------------------------------------- 1 | require 'faraday' 2 | require 'core_ext/hash/compact' 3 | 4 | module Travis 5 | module Testing 6 | require 'travis/testing/stubs' 7 | end 8 | end 9 | 10 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travis-ci/travis-api/12ee6c9a1e29360a232f8b64662859b01e98d1d4/public/favicon.ico -------------------------------------------------------------------------------- /public/images/result/canceled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travis-ci/travis-api/12ee6c9a1e29360a232f8b64662859b01e98d1d4/public/images/result/canceled.png -------------------------------------------------------------------------------- /public/images/result/error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travis-ci/travis-api/12ee6c9a1e29360a232f8b64662859b01e98d1d4/public/images/result/error.png -------------------------------------------------------------------------------- /public/images/result/failing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travis-ci/travis-api/12ee6c9a1e29360a232f8b64662859b01e98d1d4/public/images/result/failing.png -------------------------------------------------------------------------------- /public/images/result/passing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travis-ci/travis-api/12ee6c9a1e29360a232f8b64662859b01e98d1d4/public/images/result/passing.png -------------------------------------------------------------------------------- /public/images/result/pending.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travis-ci/travis-api/12ee6c9a1e29360a232f8b64662859b01e98d1d4/public/images/result/pending.png -------------------------------------------------------------------------------- /public/images/result/unknown.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travis-ci/travis-api/12ee6c9a1e29360a232f8b64662859b01e98d1d4/public/images/result/unknown.png -------------------------------------------------------------------------------- /spec/auth/report/README: -------------------------------------------------------------------------------- 1 | ``` 2 | $ ./spec/auth/report/generate 3 | $ open ./spec/auth/report/auth.html 4 | ``` 5 | -------------------------------------------------------------------------------- /spec/auth/report/generate: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export SKIP_COVERAGE=true 4 | 5 | bundle exec rspec spec/auth \ 6 | --require ./spec/auth/report/csv_formatter.rb \ 7 | --format CsvFormatter | tail -n +2 > spec/auth/report/auth.csv 8 | 9 | ruby spec/auth/report/table.rb > spec/auth/report/auth.html 10 | -------------------------------------------------------------------------------- /spec/auth/v2.1/switch_spec.rb: -------------------------------------------------------------------------------- 1 | describe 'v2.1 switch', auth_helpers: true, api_version: :'v2.1', set_app: true do 2 | let(:user) { FactoryBot.create(:user) } 3 | let(:repo) { Repository.first } 4 | 5 | describe 'by default' do 6 | describe 'GET /repos/%{repo.id}' do 7 | it(:with_permission) { should auth status: 200, type: :json, empty: false } 8 | end 9 | end 10 | 11 | describe 'disabled' do 12 | env DISABLE_V2_1: true 13 | 14 | describe 'GET /repos/%{repo.id}' do 15 | it(:with_permission) { should auth status: 406 } 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /spec/integration/uptime_spec.rb: -------------------------------------------------------------------------------- 1 | describe 'Uptime', set_app: true do 2 | it 'returns a 200 and ok when the request was successful' do 3 | response = get '/uptime' 4 | expect(response.status).to eq(200) 5 | expect(response.body).to eq("OK") 6 | end 7 | 8 | it "returns a 500 when the query wasn't successful" do 9 | allow(ActiveRecord::Base.connection).to receive(:execute).and_raise(StandardError, 'error!') 10 | response = get '/uptime' 11 | expect(response.status).to eq(500) 12 | expect(response.body).to eq("Error: error!") 13 | allow(ActiveRecord::Base.connection).to receive(:execute).and_call_original 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /spec/integration/v2/branches_spec.rb: -------------------------------------------------------------------------------- 1 | describe 'Branches', set_app: true do 2 | let(:repo) { Repository.by_slug('svenfuchs/minimal').first } 3 | let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } 4 | 5 | it 'GET /branches?repository_id=:repository_id' do 6 | response = get '/branches', { repository_id: repo.id }, headers 7 | expect(response).to deliver_json_for(repo.last_finished_builds_by_branches, version: 'v2', type: 'branches') 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/lib/model/build/config/matrix_spec.rb: -------------------------------------------------------------------------------- 1 | require 'core_ext/hash/deep_symbolize_keys' 2 | 3 | describe Build::Config::Matrix do 4 | it 'can handle nil values in exclude matrix' do 5 | expect { Build::Config::Matrix.new(matrix: { exclude: [nil] }).expand }.not_to raise_error 6 | end 7 | 8 | it 'can handle list values in exclude matrix' do 9 | expect { Build::Config::Matrix.new(matrix: []).expand }.not_to raise_error 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/lib/model/permission_spec.rb: -------------------------------------------------------------------------------- 1 | describe Permission do 2 | describe 'by_roles' do 3 | before :each do 4 | Permission::ROLES.each { |role| Permission.create!(role => true) } 5 | end 6 | 7 | it 'returns matching permissions if two roles given as symbols' do 8 | expect(Permission.by_roles([:admin, :pull]).size).to eq(3) 9 | end 10 | 11 | it 'returns a single permission if one role given' do 12 | expect(Permission.by_roles('admin').size).to eq(1) 13 | end 14 | 15 | it 'returns an empty scope if no roles given' do 16 | expect(Permission.by_roles('').size).to eq(0) 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/lib/model/token_spec.rb: -------------------------------------------------------------------------------- 1 | describe Token do 2 | it 'generate_token sets the token to a 20 character value' do 3 | expect(Token.new.send(:generate_token).length).to eq(20) 4 | end 5 | 6 | it 'does not generate new token on save' do 7 | token = Token.create! 8 | 9 | expect { 10 | token.save 11 | }.to_not change { token.token } 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/lib/services/update_user_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Services::UpdateUser do 2 | include Travis::Testing::Stubs 3 | 4 | let(:service) { described_class.new(user, params) } 5 | 6 | before :each do 7 | allow(user).to receive(:update!) 8 | end 9 | 10 | attr_reader :params 11 | 12 | it 'updates the locale if valid' do 13 | @params = { :locale => 'en' } 14 | expect(user).to receive(:update!).with(params) 15 | service.run 16 | end 17 | 18 | it 'does not update the locale if invalid' do 19 | @params = { :locale => 'foo' } 20 | expect(user).not_to receive(:update!) 21 | service.run 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/support.rb: -------------------------------------------------------------------------------- 1 | require 'support/matchers' 2 | require 'support/payloads' 3 | 4 | module Support 5 | autoload :ActiveRecord, 'support/active_record' 6 | autoload :Formats, 'support/formats' 7 | autoload :GCS, 'support/gcs' 8 | autoload :Log, 'support/log' 9 | autoload :Mocks, 'support/mocks' 10 | autoload :Notifications, 'support/notifications' 11 | autoload :Redis, 'support/redis' 12 | autoload :S3, 'support/s3' 13 | autoload :Silence, 'support/silence' 14 | end 15 | 16 | -------------------------------------------------------------------------------- /spec/support/coverage.rb: -------------------------------------------------------------------------------- 1 | unless ENV['SKIP_COVERAGE'] 2 | require 'simplecov' 3 | 4 | SimpleCov.start do 5 | coverage_dir '.coverage' 6 | add_filter "/spec/" 7 | add_group "v3", "lib/travis/api/v3" 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/support/env.rb: -------------------------------------------------------------------------------- 1 | module Support 2 | module Env 3 | def self.included(base) 4 | base.send(:extend, ClassMethods) 5 | end 6 | 7 | module ClassMethods 8 | def env(vars) 9 | before { define_env(vars) } 10 | after { undefine_env(vars) } 11 | end 12 | end 13 | 14 | def define_env(vars) 15 | vars.each { |key, value| ENV[key.to_s] = value.to_s } 16 | end 17 | 18 | def undefine_env(vars) 19 | vars.each { |key, _| ENV.delete(key.to_s) } 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /spec/support/gdpr_spec_helper.rb: -------------------------------------------------------------------------------- 1 | module Support 2 | module GdprSpecHelper 3 | def stub_gdpr_request(method, path, user_id:) 4 | url = URI(gdpr_url).tap do |url| 5 | url.path = path 6 | end.to_s 7 | stub_request(method, url).with(headers: { 'Authorization' => "Token token=\"#{gdpr_auth_token}\"", 'X-Travis-User-Id' => user_id, 'X-Travis-Source' => 'travis-api' }) 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /spec/unit/app_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::App do 2 | describe :setup? do 3 | it 'indicates if #setup has been called' do 4 | Travis::Api::App.setup 5 | expect(Travis::Api::App).to be_setup 6 | end 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /spec/unit/default_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::App::Endpoint::Home, set_app: true do 2 | describe 'GET /' do 3 | it 'replies with a json response by default' do 4 | expect(get('/')["Content-Type"]).to include("json") 5 | end 6 | 7 | it 'redirects HTML requests to /docs' do 8 | get '/', {}, 'HTTP_ACCEPT' => 'text/html' 9 | expect(status).to eq(302) 10 | expect(headers['Location']).to end_with('/docs/') 11 | end 12 | 13 | it 'does not check auth' do 14 | expect(subject.settings.check_auth?).to eq false 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/unit/endpoint/branches_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::App::Endpoint::Branches do 2 | it 'has to be tested' 3 | end 4 | -------------------------------------------------------------------------------- /spec/unit/endpoint/endpoints_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::App::Endpoint::Endpoints do 2 | it 'has to be tested' 3 | end 4 | -------------------------------------------------------------------------------- /spec/unit/endpoint/hooks_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::App::Endpoint::Hooks do 2 | it 'has to be tested' 3 | end 4 | -------------------------------------------------------------------------------- /spec/unit/extensions/expose_pattern_spec.rb: -------------------------------------------------------------------------------- 1 | class Foo < Sinatra::Base 2 | register Travis::Api::App::Extensions::ExposePattern 3 | 4 | get '/:id' do 5 | "ok" 6 | end 7 | end 8 | 9 | describe Travis::Api::App::Extensions::ExposePattern do 10 | before { set_app(Foo) } 11 | 12 | example "it exposes the pattern" do 13 | expect(get('/foo')).to be_ok 14 | expect(headers['X-Pattern']).to eq('/:id') 15 | end 16 | 17 | example "it exposes the app class" do 18 | expect(get('/foo')).to be_ok 19 | expect(headers['X-Endpoint']).to eq('Foo') 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /spec/unit/extensions/smart_constants_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::App::Extensions::SmartConstants do 2 | let(:some_app) do 3 | Sinatra.new { register Travis::Api::App::Extensions::SmartConstants } 4 | end 5 | 6 | describe :helpers do 7 | it 'works' do # :) 8 | some_app.helpers :respond_with 9 | expect(some_app.ancestors).to include(Travis::Api::App::Helpers::RespondWith) 10 | end 11 | end 12 | 13 | describe :register do 14 | it 'works' do # :) 15 | some_app.register :subclass_tracker 16 | expect(some_app).to be_a(Travis::Api::App::Extensions::SubclassTracker) 17 | end 18 | end 19 | 20 | end 21 | -------------------------------------------------------------------------------- /spec/unit/helpers/json_renderer_spec.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | # describe Travis::Api::App::Helpers::JsonRenderer do 4 | # before do 5 | # mock_app do 6 | # helpers Travis::Api::App::Helpers::JsonRenderer 7 | # get('/') { {'foo' => 'bar'} } 8 | # end 9 | # end 10 | # 11 | # it 'renders body as json' do 12 | # get('/').should be_ok 13 | # JSON.load(body).should == {'foo' => 'bar'} 14 | # end 15 | # end 16 | -------------------------------------------------------------------------------- /spec/unit/middleware/logging_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::App::Middleware::Logging do 2 | it 'configures ActiveRecord' do 3 | expect(ActiveRecord::Base.logger).to eq(Travis.logger) 4 | end 5 | 6 | it 'sets the logger' do 7 | mock_app do 8 | use Travis::Api::App::Middleware::Logging 9 | get '/check_logger' do 10 | throw unless logger == Travis.logger 11 | 'ok' 12 | end 13 | end 14 | 15 | expect(get('/check_logger')).to be_ok 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /spec/unit/model/build_spec.rb: -------------------------------------------------------------------------------- 1 | describe Build do 2 | let(:build) { FactoryBot.build(:build, state: :created) } 3 | 4 | it 'defaults state to :created' do 5 | expect(build.state.to_sym).to eq(:created) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/unit/model/job_spec.rb: -------------------------------------------------------------------------------- 1 | describe Job do 2 | let(:job) { FactoryBot.build(:job, state: nil) } 3 | 4 | it 'defaults state to :created' do 5 | expect(job.state).to eq(:created) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /spec/unit/responders/service_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::App::Responders::Service do 2 | class MyService < Travis::Api::App::Responders::Service 3 | end 4 | 5 | let(:endpoint) { double 'endpoint', public?: true } 6 | let(:resource) { double 'resource', run: {} } 7 | let(:options) { {} } 8 | let(:service) { MyService.new(endpoint, resource, options) } 9 | 10 | context 'with final resource' do 11 | before { allow(resource).to receive(:final?).and_return(true) } 12 | 13 | it 'caches resource for a year' do 14 | expect(endpoint).to receive(:expires).with(31536000, :public) 15 | service.apply 16 | end 17 | end 18 | 19 | end 20 | -------------------------------------------------------------------------------- /spec/unit/serialize/v2/http/broadcasts_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::Serialize::V2::Http::Broadcasts do 2 | include Support::Formats 3 | 4 | let(:broadcast) { double(:id => 1, :message => 'yo hey!') } 5 | let(:data) { described_class.new([broadcast]).data } 6 | 7 | it 'broadcasts' do 8 | expect(data['broadcasts'].first).to eq({ 9 | 'id' => 1, 10 | 'message' => 'yo hey!' 11 | }) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/unit/serialize/v2/http/caches_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::Serialize::V2::Http::Caches do 2 | include Travis::Testing::Stubs, Support::Formats 3 | let(:data) { described_class.new([cache]).data } 4 | 5 | specify 'caches' do 6 | expect(data['caches']).to eq([{ 7 | "repository_id" => 1, 8 | "size" => 1000, 9 | "slug" => "cache", 10 | "branch" => "master", 11 | "last_modified" => "1970-01-01T00:00:00Z" 12 | }]) 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /spec/unit/serialize/v2/http/hooks_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::Serialize::V2::Http::Hooks do 2 | include Travis::Testing::Stubs 3 | 4 | let(:data) { 5 | r = repository 6 | allow(r).to receive(:admin?).and_return(true) 7 | described_class.new([r]).data 8 | } 9 | 10 | it 'hooks' do 11 | expect(data['hooks']).to eq([ 12 | { 13 | 'id' => 1, 14 | 'name' => 'minimal', 15 | 'owner_name' => 'svenfuchs', 16 | 'description' => 'the repo description', 17 | 'active' => true, 18 | 'private' => false, 19 | 'admin' => true 20 | } 21 | ]) 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/unit/serialize/v2/http/ssl_key_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::Api::Serialize::V2::Http::SslKey do 2 | include Travis::Testing::Stubs 3 | include Support::Formats 4 | 5 | let(:key) { 6 | key = stub_key 7 | allow(key).to receive(:private_key).and_return(TEST_PRIVATE_KEY) 8 | key 9 | } 10 | let(:data) { described_class.new(key).data } 11 | 12 | it 'returns data' do 13 | expect(data['key']).to eq('-----BEGIN PUBLIC KEY-----') 14 | expect(data['fingerprint']).to eq('57:78:65:c2:c9:c8:c9:f7:dd:2b:35:39:40:27:d2:40') 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /spec/v3/error_handling_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::ServiceIndex, set_app: true do 2 | let(:headers) {{ }} 3 | let(:path) { "/v3/repo/1/activate" } 4 | let(:json) { JSON.load(response.body) } 5 | let(:response) { get(path, {}, headers) } 6 | let(:resources) { json.fetch('resources') } 7 | 8 | it "handles wrong HTTP method with 405 status" do 9 | expect(response.status).to eq(405) 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/v3/models/branch_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Models::Branch do 2 | let!(:subject) { FactoryBot.create(:branch) } 3 | 4 | it "cron should be deleted when the related branch is deleted" do 5 | cron = FactoryBot.create(:cron, branch: subject) 6 | subject.destroy 7 | expect(Travis::API::V3::Models::Cron.find_by_id(cron.id)).to be nil 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/v3/models/build_backup_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Models::BuildBackup do 2 | let(:build_backup) { FactoryBot.create(:build_backup) } 3 | subject { Travis::API::V3::Models::BuildBackup.find_by_id(build_backup.id) } 4 | 5 | example { expect(subject.file_name).to be_present } 6 | end 7 | -------------------------------------------------------------------------------- /spec/v3/models/build_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Models::Build do 2 | let(:build) { FactoryBot.create(:build, state: nil) } 3 | subject { Travis::API::V3::Models::Build.find_by_id(build.id) } 4 | 5 | example { expect(subject.state).to eq 'created' } 6 | 7 | describe 'casting sender to V3 model' do 8 | let(:sender) { FactoryBot.create(:user) } 9 | 10 | before do 11 | subject.update(sender_type: 'User', sender_id: sender.id) 12 | end 13 | 14 | it 'always returns a V3 namespaced sender instance' do 15 | expect(subject.created_by).to be_a Travis::API::V3::Models::User 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /spec/v3/models/credits_calculator_config_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Models::CreditsResult do 2 | let(:user) { FactoryBot.create(:user) } 3 | let(:attributes) do 4 | { 5 | 'users' => 5, 6 | 'minutes' => 1200, 7 | 'os' => 'linux', 8 | 'instance_size' => '2x-large' 9 | } 10 | end 11 | 12 | subject { Travis::API::V3::Models::CreditsCalculatorConfig.new(attributes) } 13 | 14 | context 'basic fields' do 15 | it 'returns basic fields' do 16 | attributes.each do |key, value| 17 | expect(subject.send(key)).to eq(value) 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /spec/v3/models/credits_result_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Models::CreditsResult do 2 | let(:user) { FactoryBot.create(:user) } 3 | let(:attributes) do 4 | { 5 | 'users' => 5, 6 | 'minutes' => 1200, 7 | 'os' => 'linux', 8 | 'instance_size' => '2x-large', 9 | 'credits' => 25_000, 10 | 'price' => 1_500 11 | } 12 | end 13 | 14 | subject { Travis::API::V3::Models::CreditsResult.new(attributes) } 15 | 16 | context 'basic fields' do 17 | it 'returns basic fields' do 18 | attributes.each do |key, value| 19 | expect(subject.send(key)).to eq(value) 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /spec/v3/models/job_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Models::Job do 2 | let(:job) { FactoryBot.create(:job, state: nil) } 3 | subject { Travis::API::V3::Models::Job.find_by_id(job.id).state } 4 | 5 | it { should eq 'created' } 6 | end 7 | -------------------------------------------------------------------------------- /spec/v3/queries/build_backups_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Queries::BuildBackups do 2 | subject { described_class.new({ 'build_backups.repository_id' => repo.id }, 'BuildBackups') } 3 | 4 | describe '#all' do 5 | let(:repo) { FactoryBot.create(:repository) } 6 | let!(:build_backup) { FactoryBot.create(:build_backup, repository: repo) } 7 | 8 | it 'returns backups for repo' do 9 | backups = subject.all 10 | 11 | expect(backups.first.file_name).to eq(build_backup.file_name) 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /spec/v3/queries/organization_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Queries::Organization do 2 | it 'fetches the newest user if multiple users exist with the same login' do 3 | FactoryBot.create(:org, login: 'travisbot') 4 | newer = FactoryBot.create(:org, login: 'travisbot') 5 | 6 | expect(described_class.new({ 'organization.login' => 'travisbot' }, 'Organization').find.id).to eq(newer.id) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /spec/v3/queries/user_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Queries::User do 2 | it 'fetches the newest user if multiple users exist with the same login' do 3 | FactoryBot.create(:user, login: 'travisbot') 4 | newer = FactoryBot.create(:user, login: 'travisbot') 5 | 6 | expect(described_class.new({ 'user.login' => 'travisbot' }, 'User').find.id).to eq(newer.id) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /spec/v3/result_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Result do 2 | let(:access_control) { Object.new } 3 | subject(:result) { described_class.new(access_control: access_control, type: :example, resource: []) } 4 | 5 | example { expect(result.type) .to be == :example } 6 | example { expect(result.resource) .to be == [] } 7 | example { expect(result.example) .to be == [] } 8 | example { expect(result.access_control) .to be == access_control } 9 | end 10 | -------------------------------------------------------------------------------- /spec/v3/services/access_token/remove_token_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Services::AccessToken::RemoveToken, set_app: true do 2 | let(:user) { FactoryBot.create(:user) } 3 | let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: 0) } 4 | let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}" }} 5 | let(:parsed_body) { JSON.load(body) } 6 | 7 | describe "deleting the API access token" do 8 | before { delete('/v3/access_token', {}, headers) } 9 | example { expect(last_response.status).to eq 204 } 10 | example { expect(Travis.redis.exists?("t:#{token}")).to be_falsey } 11 | example { expect(parsed_body).to be_nil } 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/v3/services/user/logout_spec.rb: -------------------------------------------------------------------------------- 1 | describe Travis::API::V3::Services::User::Logout, set_app: true do 2 | let(:user) { Travis::API::V3::Models::User.find_by_login('svenfuchs') } 3 | 4 | let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: 1) } 5 | let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}" }} 6 | before { stub_request(:post, %r((.+)/usage/stats)) } 7 | 8 | describe "logout user" do 9 | before { get("/v3/logout", {}, headers) } 10 | before { get("/v3/user", {}, headers) } 11 | example { expect(last_response).not_to be_ok } 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /tmp/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/travis-ci/travis-api/12ee6c9a1e29360a232f8b64662859b01e98d1d4/tmp/.gitkeep --------------------------------------------------------------------------------