Skip to content

Commit

Permalink
Merge branch 'origin/develop' into 'fb-leap-383'
Browse files Browse the repository at this point in the history
  • Loading branch information
juliosgarbi committed Dec 8, 2023
2 parents 99e0c3c + 635898d commit f219cd2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/jira-command.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "/git command"
name: "/jira command"

on:
repository_dispatch:
Expand Down
28 changes: 24 additions & 4 deletions .github/workflows/slash-command-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ env:
git
jira
issue_commands_list: |
jira
jobs:
slashCommandDispatch:
if: startsWith(github.event.comment.body, '/')
Expand All @@ -24,25 +27,42 @@ jobs:
uses: actions/github-script@v7
env:
COMMANDS_LIST: ${{ env.commands_list }}
ISSUE_COMMANDS_LIST: ${{ env.issue_commands_list }}
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const body = context.payload.comment.body.toLowerCase().trim()
const commands_list = process.env.COMMANDS_LIST.split("\n")
const issue_commands_list = process.env.ISSUE_COMMANDS_LIST.split("\n")
console.log("Detected PR comment: " + body)
console.log("Commands list: " + commands_list)
console.log("Issue commands list: " + issue_commands_list)
commandArray = body.split(/\s+/)
const contextCommand = commandArray[0].split('/')[1].trim();
console.log("contextCommand: " + contextCommand)
core.setOutput('command_state', 'known')
core.setOutput('is_issue_command', 'false')
if (! commands_list.includes(contextCommand)) {
core.setOutput('command_state', 'unknown')
core.setOutput('command', contextCommand)
}
if (issue_commands_list.includes(contextCommand)) {
core.setOutput('is_issue_command', 'true')
}
- name: Slash Command Dispatch for Issues
id: scd_issues
if: ${{ steps.determine_command.outputs.command_state != 'unknown' && steps.determine_command.outputs.is_issue_command == 'true' }}
uses: peter-evans/slash-command-dispatch@v3
with:
token: ${{ secrets.GIT_PAT }}
issue-type: "issue"
reactions: true
commands: ${{ env.issue_commands_list }}

- name: Slash Command Dispatch
id: scd
if: ${{ steps.determine_command.outputs.command_state != 'unknown' }}
- name: Slash Command Dispatch for PRs
id: scd_prs
if: ${{ steps.determine_command.outputs.command_state != 'unknown' && steps.determine_command.outputs.is_issue_command != 'true' }}
uses: peter-evans/slash-command-dispatch@v3
with:
token: ${{ secrets.GIT_PAT }}
Expand All @@ -56,6 +76,6 @@ jobs:
with:
comment-id: ${{ github.event.comment.id }}
body: |
> '/${{ steps.determine_command.outputs.command }}' is unknown command.
> '/${{ steps.determine_command.outputs.command }}' is an unknown command.
> See '/help'
reactions: eyes, confused
10 changes: 4 additions & 6 deletions label_studio/core/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import calendar
import contextlib
import copy
import hashlib
import logging
import os
import random
Expand Down Expand Up @@ -43,6 +42,7 @@
pre_save,
)
from django.db.utils import OperationalError
from django.utils.crypto import get_random_string
from django.utils.module_loading import import_string
from django_filters.rest_framework import DjangoFilterBackend
from drf_yasg.inspectors import CoreAPICompatInspector, NotHandled
Expand Down Expand Up @@ -135,11 +135,9 @@ def custom_exception_handler(exc, context):
return response


def create_hash():
"""This function generate 40 character long hash"""
h = hashlib.sha512()
h.update(str(time.time()).encode('utf-8'))
return h.hexdigest()[0:16]
def create_hash() -> str:
"""This function creates a secure token for the organization"""
return get_random_string(length=40)


def paginator(objects, request, default_page=1, default_size=50):
Expand Down
2 changes: 1 addition & 1 deletion label_studio/organizations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def remove_user(self, user):

def reset_token(self):
self.token = create_hash()
self.save()
self.save(update_fields=['token'])

def check_max_projects(self):
"""This check raise an exception if the projects limit is hit"""
Expand Down
2 changes: 1 addition & 1 deletion label_studio/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def find_by_invite_url(cls, url):

def reset_token(self):
self.token = create_hash()
self.save()
self.save(update_fields=['token'])

def add_collaborator(self, user):
created = False
Expand Down
16 changes: 8 additions & 8 deletions label_studio/tasks/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,28 @@ def _fill_annotations_project(project_id):
def fill_annotations_project():
logger.info('Start filling project field for Annotation model')

projects = Project.objects.all().only('id')
for project in projects:
start_job_async_or_sync(_fill_annotations_project, project.id)
project_ids = Project.objects.all().values_list('id', flat=True)
for project_id in project_ids:
start_job_async_or_sync(_fill_annotations_project, project_id)

logger.info('Finished filling project field for Annotation model')


def _fill_predictions_project(migration_name='0043_auto_20230825'):
projects = Project.objects.all().only('id')
for project in projects:
project_ids = Project.objects.all().values_list('id', flat=True)
for project_id in project_ids:
migration = AsyncMigrationStatus.objects.create(
project=project,
project_id=project_id,
name=migration_name,
status=AsyncMigrationStatus.STATUS_STARTED,
)

updated_count = Prediction.objects.filter(task__project_id=project.id).update(project_id=project.id)
updated_count = Prediction.objects.filter(task__project_id=project_id).update(project_id=project_id)

migration.status = AsyncMigrationStatus.STATUS_FINISHED
migration.meta = {
'predictions_processed': updated_count,
'total_project_predictions': project.predictions.count(),
'total_project_predictions': Prediction.objects.filter(project_id=project_id).count(),
}
migration.save()

Expand Down

0 comments on commit f219cd2

Please sign in to comment.