Skip to content

Commit 5fc5786

Browse files
Merge pull request #56 from SuffolkLITLab/docstring-github-feedback
Enhance docstring to clarify the different parameters and their purpose
2 parents 9f8787f + 8294642 commit 5fc5786

File tree

1 file changed

+58
-8
lines changed

1 file changed

+58
-8
lines changed

docassemble/GithubFeedbackForm/github_issue.py

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def valid_github_issue_config():
4040

4141

4242
def feedback_link(
43-
user_info_object=None,
43+
user_info_object: Optional[Any] = None,
4444
i: Optional[str] = None,
4545
github_repo: Optional[str] = None,
4646
github_user: Optional[str] = None,
@@ -50,15 +50,56 @@ def feedback_link(
5050
filename: Optional[str] = None,
5151
) -> str:
5252
"""
53-
Helper function to get a link to the GitHub feedback form.
54-
For simple usage, it should be enough to call
55-
`feedback_link(user_info(), github_user="MY_USER_OR_ORG_ON_GITHUB")`, so long as the package you
56-
want to provide feedback on exists on GitHub and you are running from an "installed" (not playground)
57-
link.
53+
Constructs a URL that when visited will open the feedback interview with the correct context, including
54+
the destination repository for the feedback and information about the user's current position in the interview.
55+
56+
The feedback interview needs to know the URL to the github repository where the feedback will be made, and
57+
uses a few alternative methods to determine the two components of that url - the owner of the repository and the name of the repository.
58+
For example, suppose you want to see the issues when you visit https://github.com/suffolklitlab/docassemble-AssemblyLine/issues:
59+
60+
To determine the feedback destination repository's name, e.g., docassemble-AssemblyLine:
61+
62+
1. It tries using the output of current_context() (formerly user_info()), if passed as the user_info_object parameter,
63+
to retrieve the package's name. It also tries to get the variable, question_id,
64+
filename, and session ID from the user_info_object. Note if you want to test the feedback from during development, the package name is not available
65+
when running from the playground.
66+
2. It uses the value of the github_repo parameter.
67+
3. It defaults to the demo repository on the suffolklitlab-issues organization.
68+
69+
To determine the feedback destination repository's owner, e.g., suffolklitlab:
70+
71+
1. It uses the value of the github_user parameter.
72+
2. It tries to get the default repository owner from the Docassemble config, at github issues: default repository owner.
73+
3. It defaults to suffolklitlab-issues.
74+
75+
The variable, question_id, package_version, and filename parameters can also be passed in manually rather than retrieved from the
76+
user_info_object parameter.
77+
78+
Args:
79+
user_info_object (str, optional): the output of the current_context() function, which might contain enough information to create the link.
80+
(Name is historical as the current_context() function replaces the former user_info() function)
81+
i (str, optional): path to the feedback interview file, e.g., docassemble.GithubFeedbackForm:feedback.yml
82+
github_repo (str, optional): GitHub repository name where issue feedback will be made. E.g, docassemble-AssemblyLine
83+
github_user (str, optional): GitHub user or organization name where issue feedback will be made. E.g, suffolklitlab
84+
variable (str, optional): the variable name that the feedback is about
85+
question_id (str, optional): the question ID that the feedback is about
86+
package_version (str, optional): the version of the package that the feedback is about
87+
filename (str, optional): the YAML interview filename that the feedback is about
88+
89+
Returns:
90+
str: a URL to the feedback form that includes the public URL parameters for the feedback interview
91+
92+
Example:
93+
feedback_link(current_context(), i="docassemble.GithubFeedbackForm:feedback.yml") # github_user is taken from the config and github_repo inferred from output of current_context()
94+
95+
The package name isn't available from the user_info_object when you run from the playground, so it is better to pass in the github_repo parameter manually
96+
for better interactive testing:
97+
98+
feedback_link(current_context(), github_repo="docassemble-AssemblyLine", github_user="suffolklitlab", variable="my_variable", question_id="my_question", package_version="1.0.0", filename="my_file.py", i="docassemble.GithubFeedbackForm:feedback.yml")
5899
"""
59100
if user_info_object:
60101
package_name = str(user_info_object.package)
61-
# TODO: we can use the packages table or /api/packages to get the exact GitHub URL
102+
# TODO: maybe we can use the packages table or /api/packages to get the exact GitHub URL, which would include the owner
62103
if package_name and not package_name.startswith("docassemble-playground"):
63104
_github_repo = package_name.replace(".", "-")
64105
else:
@@ -77,20 +118,28 @@ def feedback_link(
77118
"default repository owner"
78119
)
79120
_session_id = user_info_object.session
121+
else:
122+
_session_id = None
80123

81-
# Allow keyword params to override any info from the user_info() object
124+
# Allow keyword params to override any info from the current_context() object
82125
# We will try pulling the repo owner name from the Docassemble config
83126
if github_repo and github_user:
84127
_github_repo = github_repo
85128
_github_user = github_user
86129
elif (
87130
get_config("github issues", {}).get("default repository owner") and github_repo
88131
):
132+
log(
133+
"No github_user provided, using default repository owner from config to get the feedback"
134+
)
89135
_github_user = get_config("github issues", {}).get("default repository owner")
90136
_github_repo = github_repo
91137
else:
92138
_github_repo = "demo"
93139
_github_user = "suffolklitlab-issues"
140+
log(
141+
"No github_repo provided, using default demo repository to get the feedback"
142+
)
94143
if variable:
95144
_variable = variable
96145
if question_id:
@@ -102,6 +151,7 @@ def feedback_link(
102151

103152
if not i:
104153
i = "docassemble.GithubFeedbackForm:feedback.yml"
154+
log("No feedback interview file provided, using default feedback interview")
105155

106156
return interview_url(
107157
i=i,

0 commit comments

Comments
 (0)