Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dimitri Podborski
AutomationTools
Commits
cf6c5c64
Commit
cf6c5c64
authored
Mar 19, 2021
by
Dimitri Podborski
Browse files
Add option for mentioning authors in issues
close
#191
parent
899ed7ce
Changes
2
Hide whitespace changes
Inline
Side-by-side
automation/helpers.py
View file @
cf6c5c64
...
...
@@ -4,6 +4,7 @@ Some helper functions
'''
import
json
import
os
import
re
from
datetime
import
datetime
,
timedelta
from
docx
import
Document
,
opc
,
oxml
,
shared
from
docx.enum.text
import
WD_ALIGN_PARAGRAPH
# pylint: disable=E0611
...
...
@@ -258,4 +259,22 @@ def get_updated_issue_description(current_decription, document, details):
return
None
description
=
create_issue_description_header
(
document
,
details
)
description
+=
current_decription
[
pos1
+
len
(
CLOSING_TAG
):]
return
description
\ No newline at end of file
return
description
def
find_gitlab_users
(
gitlab_users
,
document
):
usernames
=
[]
regex
=
re
.
compile
(
r
'[^a-zA-Z\s]'
)
try
:
for
author
in
document
[
'authors'
]:
author_name
=
author
[
'name'
].
lower
().
strip
()
author_name
=
regex
.
sub
(
''
,
author_name
)
# remove non alphabetic chars
author_name
=
' '
.
join
(
[
w
for
w
in
author_name
.
split
()
if
len
(
w
)
>
1
]
)
# remove single letters
for
key
in
gitlab_users
:
gl_name
=
gitlab_users
[
key
][
'name'
].
lower
().
strip
()
gl_name
=
regex
.
sub
(
''
,
gl_name
)
# remove non alphabetic chars
gl_name
=
' '
.
join
(
[
w
for
w
in
gl_name
.
split
()
if
len
(
w
)
>
1
]
)
# remove single letters
if
author_name
==
gl_name
:
usernames
.
append
(
key
)
except
:
return
[]
return
usernames
systems.py
View file @
cf6c5c64
...
...
@@ -38,16 +38,6 @@ GITLAB_USERS_PATH = os.path.join(DATA_PATH, 'gitlab_users.json')
MEETINGS_PATH
=
os
.
path
.
join
(
DATA_PATH
,
'meetings.json'
)
SYSTEMS_GROUP_ID
=
727
# GitLab Group ID for Systems Subgroup
class
Entry
:
number
:
str
project_or_url
:
str
# doc = Entry()
# doc.title = 'asdf'
# print(doc)
def
print_infos
(
table_entries
):
print
(
'
\n
Dump information'
)
for
entry
in
table_entries
:
...
...
@@ -99,13 +89,17 @@ def print_infos(table_entries):
last_comment
=
max
(
comments
,
key
=
lambda
x
:
x
.
id
)
print
(
' Last comment from'
,
last_comment
.
author
[
'username'
],
'at'
,
last_comment
.
updated_at
)
def
open_new_issue
(
project_id
,
document
,
test
,
meeting_start
):
def
open_new_issue
(
project_id
,
document
,
test
,
meeting_start
,
gitlab_members
):
usernames
=
helpers
.
find_gitlab_users
(
gitlab_members
,
document
)
issue_title
=
helpers
.
create_issue_title
(
document
)
document_details
=
mdms
.
get_document_details
(
document
[
'mdms_id'
])
if
document_details
is
None
:
print
(
' Skip'
,
document
[
'document'
])
return
issue_description
=
helpers
.
create_issue_description
(
document
,
document_details
)
if
len
(
usernames
)
>
0
:
issue_description
+=
'
\n
_for:_ '
+
''
.
join
(
'@'
+
str
(
u
)
+
', '
for
u
in
usernames
)
print
(
issue_description
)
issue_lables
=
[]
timestamp
=
datetime
.
now
()
if
len
(
document_details
[
'documents'
])
>
0
:
...
...
@@ -138,9 +132,8 @@ def open_issues(table_entries, test, gitlab_members, meeting_start):
issues
=
gitlab
.
get_issues
(
project_id
)
issue_with_title
,
issue_with_meta
,
meta_last_doc_version
=
helpers
.
find_issue
(
issues
,
document
)
# TODO find gitlab_members and add them to the issue description, this will automatically notify the contributors
if
issue_with_title
is
None
and
issue_with_meta
is
None
:
open_new_issue
(
project_id
,
document
,
test
,
meeting_start
)
open_new_issue
(
project_id
,
document
,
test
,
meeting_start
,
gitlab_members
)
counter
+=
1
elif
issue_with_title
is
not
None
and
issue_with_meta
is
None
:
print
(
' * {}: ATTENTION Another issue with the same document number in the title was found on GitLab.'
.
format
(
document
[
'document'
]))
...
...
@@ -149,7 +142,7 @@ def open_issues(table_entries, test, gitlab_members, meeting_start):
print
(
' - Should we still open a new one?'
)
user_input
=
input
(
' Type y or n: '
)
if
'y'
in
user_input
:
open_new_issue
(
project_id
,
document
,
test
,
meeting_start
)
open_new_issue
(
project_id
,
document
,
test
,
meeting_start
,
gitlab_members
)
counter
+=
1
else
:
print
(
' * {} Skip "{}"'
.
format
(
document
[
'document'
],
document
[
'title'
]))
...
...
@@ -357,6 +350,7 @@ parser.add_argument('-p', '--project', help='GitLab project URL or "SubGroup/Pro
parser
.
add_argument
(
'--meeting'
,
help
=
'MPEG meeting number. If not set, the latest meeting is used.'
,
default
=-
1
,
type
=
int
)
parser
.
add_argument
(
'-t'
,
'--template'
,
help
=
'Document template path if you want to use your .docx template for output document.'
,
type
=
str
)
parser
.
add_argument
(
'--test'
,
help
=
'Test mode. If set, no issues will be opened or closed.'
,
action
=
'store_true'
)
parser
.
add_argument
(
'-n'
,
'--notify'
,
help
=
'Notify (@mention) authors in opened issues.'
,
action
=
'store_true'
)
args
=
parser
.
parse_args
()
if
not
args
.
open
and
not
args
.
docx
and
not
args
.
close
and
not
args
.
list
:
...
...
@@ -422,6 +416,8 @@ if args.list:
print_infos
(
table_entries
)
if
args
.
open
:
meeting_start
=
helpers
.
try_parsing_date
(
meeting
[
'start_date'
])
if
not
args
.
notify
:
gitlab_members
=
None
open_issues
(
table_entries
,
args
.
test
,
gitlab_members
,
meeting_start
)
if
args
.
close
:
close_issues
(
table_entries
,
args
.
test
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment