-
Notifications
You must be signed in to change notification settings - Fork 61
Add the option to raise issue when license submission failed #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: python3
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -354,6 +354,21 @@ def createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseCommen | |
| return r.status_code | ||
|
|
||
|
|
||
| def createErrorIssue(occured_at, made_by, error_message, license_text, token): | ||
| """ View for creating an GitHub issue | ||
| with the complete Error Report to the | ||
| SPDX Online tools repository. | ||
| """ | ||
|
|
||
| body = "**1.** Occured At: {0}\n**2.** Made By: {1}\n**3.** Error Message: {2}\n**4.** License Text: {3}\n".format(occured_at, made_by, error_message, license_text) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it's easier to do this with a multiline string
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I would recommend to use multiline string |
||
| title = "Error Report" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets not directly assign a title. Keep a string constant. Similary for url - construct it from other url or keep it as setting in settings.py
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kept the url as setting in the settings.py. What about the title of the issue? Should we just kept it blank?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Title should included license name/id |
||
| payload = {'title' : title, 'body': body} | ||
| headers = {'Authorization': 'token ' + token} | ||
| url = "https://api.github.com/repos/spdx/spdx-online-tools/issues" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking around it seems that this URL is constructed out of the settings on top, we perhaps should follow the pattern they use. Not fully relevant to this PR, but I would assume you can combine a bunch of things into a single "submit-to-api" function... |
||
| r = requests.post(url, data=json.dumps(payload), headers=headers) | ||
| return r.status_code | ||
|
|
||
|
|
||
| def postToGithub(message, encodedContent, filename): | ||
| """ Function to create a new file on with encodedContent | ||
| """ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,10 +191,9 @@ def submitNewLicense(request): | |
| """ Other errors raised """ | ||
| logger.error(str(format_exc())) | ||
| if (request.is_ajax()): | ||
| ajaxdict["type"] = "error" | ||
| ajaxdict["data"] = "Unexpected error, please email the SPDX technical workgroup that the following error has occurred: " + format_exc() | ||
| response = dumps(ajaxdict) | ||
| return HttpResponse(response,status=500) | ||
| ajaxdict['error'] = str(format_exc()) | ||
| ajaxdict['inputlicensetext'] = request.POST['text'] | ||
| return JsonResponse(ajaxdict) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the caller expects "type" and "data" field now?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Ugtan What about this?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rtgdk No. I had to use Json response to get the data after making a ajax request in order to give them the ability to choose if they want to submit it or not. |
||
| return HttpResponse("Unexpected error, please email the SPDX technical workgroup that the following error has occurred: " + format_exc(), status=500) | ||
| else: | ||
| email="" | ||
|
|
@@ -1101,35 +1100,47 @@ def issue(request): | |
| try: | ||
| github_login = user.social_auth.get(provider='github') | ||
| token = github_login.extra_data["access_token"] | ||
| licenseAuthorName = request.POST['licenseAuthorName'] | ||
| licenseName = request.POST['licenseName'] | ||
| licenseIdentifier = request.POST['licenseIdentifier'] | ||
| licenseOsi = request.POST['licenseOsi'] | ||
| licenseSourceUrls = request.POST.getlist('licenseSourceUrls') | ||
| licenseExamples = request.POST.getlist('exampleUrl') | ||
| licenseHeader = request.POST['licenseHeader'] | ||
| licenseComments = request.POST['comments'] | ||
| licenseText = request.POST['inputLicenseText'] | ||
| userEmail = request.POST['userEmail'] | ||
| licenseNotes = request.POST['licenseNotes'] | ||
| listVersionAdded = request.POST['listVersionAdded'] | ||
| matchId = request.POST['matchIds'] | ||
| diffUrl = request.POST['diffUrl'] | ||
| msg = request.POST.get('msg', None) | ||
| urlType = utils.NORMAL | ||
| data = {} | ||
| xml = generateLicenseXml(licenseOsi, licenseIdentifier, licenseName, | ||
| listVersionAdded, licenseSourceUrls, licenseHeader, licenseNotes, licenseText) | ||
| now = datetime.datetime.now() | ||
| licenseRequest = LicenseRequest(licenseAuthorName=licenseAuthorName, fullname=licenseName, shortIdentifier=licenseIdentifier, | ||
| submissionDatetime=now, userEmail=userEmail, notes=licenseNotes, xml=xml) | ||
| licenseRequest.save() | ||
| licenseRequestId = licenseRequest.id | ||
| serverUrl = request.build_absolute_uri('/') | ||
| licenseRequestUrl = os.path.join(serverUrl, reverse('license-requests')[1:], str(licenseRequestId)) | ||
| statusCode = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType, matchId, diffUrl, msg) | ||
| data['statusCode'] = str(statusCode) | ||
| return JsonResponse(data) | ||
|
|
||
| if request.POST.get('error',None): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move the main part to utils.py |
||
| occured_at = datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%d") | ||
| made_by = github_login.extra_data['login'] | ||
| error_message = request.POST['error'] | ||
| license_text = request.POST['inputlicensetext'] | ||
| data = {} | ||
| statusCode = utils.createErrorIssue(occured_at, made_by, error_message, license_text, token) | ||
| data['statusCode'] = str(statusCode) | ||
| return JsonResponse(data) | ||
| else: | ||
| licenseAuthorName = request.POST['licenseAuthorName'] | ||
| licenseName = request.POST['licenseName'] | ||
| licenseIdentifier = request.POST['licenseIdentifier'] | ||
| licenseOsi = request.POST['licenseOsi'] | ||
| licenseSourceUrls = request.POST.getlist('licenseSourceUrls') | ||
| licenseExamples = request.POST.getlist('exampleUrl') | ||
| licenseHeader = request.POST['licenseHeader'] | ||
| licenseComments = request.POST['comments'] | ||
| licenseText = request.POST['inputLicenseText'] | ||
| userEmail = request.POST['userEmail'] | ||
| licenseNotes = request.POST['licenseNotes'] | ||
| listVersionAdded = request.POST['listVersionAdded'] | ||
| matchId = request.POST['matchIds'] | ||
| diffUrl = request.POST['diffUrl'] | ||
| msg = request.POST.get('msg', None) | ||
| urlType = utils.NORMAL | ||
| data = {} | ||
| xml = generateLicenseXml(licenseOsi, licenseIdentifier, licenseName, | ||
| listVersionAdded, licenseSourceUrls, licenseHeader, licenseNotes, licenseText) | ||
| now = datetime.datetime.now() | ||
| licenseRequest = LicenseRequest(licenseAuthorName=licenseAuthorName, fullname=licenseName, shortIdentifier=licenseIdentifier, | ||
| submissionDatetime=now, userEmail=userEmail, notes=licenseNotes, xml=xml) | ||
| licenseRequest.save() | ||
| licenseRequestId = licenseRequest.id | ||
| serverUrl = request.build_absolute_uri('/') | ||
| licenseRequestUrl = os.path.join(serverUrl, reverse('license-requests')[1:], str(licenseRequestId)) | ||
| statusCode = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType, matchId, diffUrl, msg) | ||
| data['statusCode'] = str(statusCode) | ||
| return JsonResponse(data) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if you can simplify the code by moving the return outside of the if. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can actually avoid a bunch of repetition by moving other things out of this if.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. I will do it. |
||
|
|
||
| except UserSocialAuth.DoesNotExist: | ||
| """ User not authenticated with GitHub """ | ||
| if (request.is_ajax()): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please contact spdx-legal@lists.spdx.orgThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have constant variable with these message which can be referenced here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate a bit please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having all these string message in one file and then referencing here in javascript.