def sync_versions(project): """ Sync the versions of a repo using its latest version. This doesn't register a new build, but clones the repo and syncs the versions. Due that `sync_repository_task` is bound to a version, we always pass the default version. :returns: The version slug that was used to trigger the clone. :rtype: str """ try: version_identifier = project.get_default_branch() version = ( project.versions.filter( identifier=version_identifier, ).first() ) if not version: log.info('Unable to sync from %s version', version_identifier) return None sync_repository_task.delay(version.pk) return version.slug except Exception: log.exception('Unknown sync versions exception') return None
def _build_url(url, projects, branches): """ Map a URL onto specific projects to build that are linked to that URL. Check each of the ``branches`` to see if they are active and should be built. """ ret = '' all_built = {} all_not_building = {} # This endpoint doesn't require authorization, we shouldn't allow builds to # be triggered from this any longer. Deprecation plan is to selectively # allow access to this endpoint for now. if not any(_allow_deprecated_webhook(project) for project in projects): return HttpResponse('This API endpoint is deprecated', status=403) for project in projects: (built, not_building) = build_branches(project, branches) if not built: # Call sync_repository_task to update tag/branch info version = project.versions.get(slug=LATEST) sync_repository_task.delay(version.pk) msg = '(URL Build) Syncing versions for %s' % project.slug log.info(msg) all_built[project.slug] = built all_not_building[project.slug] = not_building for project_slug, built in list(all_built.items()): if built: msg = '(URL Build) Build Started: {} [{}]'.format( url, ' '.join(built), ) log_info(project_slug, msg=msg) ret += msg for project_slug, not_building in list(all_not_building.items()): if not_building: msg = '(URL Build) Not Building: {} [{}]'.format( url, ' '.join(not_building), ) log_info(project_slug, msg=msg) ret += msg if not ret: ret = '(URL Build) No known branches were pushed to.' return HttpResponse(ret)