Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Learn Renku
Teaching on Renku
Advanced teaching automation
Commits
ffa01d8b
Commit
ffa01d8b
authored
Mar 14, 2022
by
Cyril Matthey-Doret
Browse files
add script to send feedback to students as issues
parent
9c6f8037
Pipeline
#328358
passed with stage
in 13 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
teach_utils/send_feedback.py
0 → 100644
View file @
ffa01d8b
#!/usr/bin/env python3
# This script sends feedback to students' forks by opening issues with the Gitlab API
# The target forks and associated metadata are read from stdin. The script expects JSON
# data as outputted by collect_forks.py
# The issues are based on a template, with the content read from a separate CSV table
# with columns "id", "grade", "comments"
import
sys
import
json
import
requests
import
click
import
pandas
as
pd
from
teach_utils.common_requests
import
parse_repo_url
FEEDBACK_TEMPLATE
=
"""
# {project}, group {group}
Please find below your grade and specific comments for this project:
## Grade:
{grade}
## Comments:
{comments}
"""
@
click
.
command
()
@
click
.
argument
(
"feedback"
,
type
=
click
.
Path
(
exists
=
True
))
@
click
.
argument
(
"forks"
,
type
=
click
.
File
(
mode
=
"r"
),
default
=
sys
.
stdin
)
@
click
.
option
(
"--token"
,
type
=
click
.
Path
(
exists
=
True
),
help
=
"Path to a file containing the Gitlab API token. If not provided, you will be prompted for the token."
,
)
def
main
(
forks
,
feedback
,
token
):
"""
Send feedback to repositories in input JSON by opening issues.
The feedback table should be a CSV file with columns "id", "grade" and "comments".
The id column should match a gitlab project ID from the JSON input
"""
# Build header with authentication token
if
token
is
None
:
token
=
click
.
prompt
(
"Please enter your Gitlab API token"
,
hide_input
=
True
)
else
:
token
=
open
(
token
).
read
().
strip
()
header
=
{
"PRIVATE-TOKEN"
:
token
}
forks
=
json
.
load
(
forks
)
feedback
=
pd
.
read_csv
(
feedback
)
for
fork
in
forks
:
# Replace content for current project in issue template
base
,
group
,
repo
=
parse_repo_url
(
fork
[
"url"
])
grade
,
comments
=
feedback
.
loc
[
feedback
[
"id"
]
==
fork
[
"id"
],
[
"grade"
,
"comments"
]
].
values
[
0
]
description
=
FEEDBACK_TEMPLATE
.
format
(
project
=
repo
,
group
=
group
,
grade
=
grade
,
comments
=
comments
)
# Create issue
requests
.
post
(
f
"
{
base
}
/api/v4/projects/
{
fork
[
'id'
]
}
/issues?confidential=true&title=Feedback"
,
headers
=
header
,
data
=
{
"description"
:
description
},
)
if
__name__
==
"__main__"
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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