Skip to content
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

Fixing Redirect on Successful License Submission #450

Merged
merged 8 commits into from
Jun 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def submit_license(request):
if 'urlType' in request.POST:
# This is present only when executing submit license via tests
urlType = request.POST["urlType"]
statusCode = createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseRequestUrl, token, urlType)
statusCode, githubIssueId = createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseRequestUrl, token, urlType)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6% of developers fix this issue

E501: line too long (200 > 79 characters)


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

18% of developers fix this issue

E1120: No value for argument 'urlType' in function call


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sonatype-lift ignoreall

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ignoreall command is active on this PR, all the existing Lift issues are ignored.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

11% of developers fix this issue

reportGeneralTypeIssues: Argument missing for parameter "urlType"


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

if str(statusCode) == '201':
result = "Success! The license request has been successfully submitted."
query.result = result
Expand Down
9 changes: 6 additions & 3 deletions src/app/templates/app/submit_new_license.html
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,15 @@
data: form,
success: function (data) {
var githubCode = data.statusCode;
var githubIssueId = data.issueId;
var githubUrl = "https://github.com/spdx/licnse-list-xml/issues/";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there is a typo here resulting in a 404 on redirect: licnse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @whot for pointing out the error, I will crate a PR to solve this

if(githubCode == '201'){
var successMessage = "The license request has been successfully submitted.";
$("#messages").html('<div class="alert alert-success alert-dismissable fade in"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Success! </strong>'+ successMessage +'</div>');
setTimeout(function() {
$("#messages").html("");
}, 7000);
setTimeout(function() {
$("#messages").html("");
}, 7000);
window.open(githubUrl + githubIssueId, "_blank");
}
else if(githubCode == '409'){
var matchType = data.matchType;
Expand Down
19 changes: 18 additions & 1 deletion src/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,24 @@ def createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseCommen
headers = {'Authorization': 'token ' + token}
url = "{0}/issues".format(TYPE_TO_URL_LICENSE[urlType])
r = requests.post(url, data=json.dumps(payload), headers=headers)
return r.status_code
status_code = r.status_code
response_json = {}
issue_id = ""

if status_code in [200, 201]:
try:
response_json = r.json()
except ValueError:
# Handle JSON parsing error
return None, None


if status_code in [200, 201] and "number" in response_json:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9% of developers fix this issue

E303: too many blank lines (2)


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

issue_id = response_json["number"]
else:
issue_id = None

return status_code, issue_id


def postToGithub(message, encodedContent, filename):
Expand Down
19 changes: 16 additions & 3 deletions src/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def submitNewLicense(request):
"""
context_dict = {}
ajaxdict = {}
githubIssueId = ""
if request.method=="POST":
if not request.user.is_authenticated:
if (request.is_ajax()):
Expand Down Expand Up @@ -162,7 +163,11 @@ def submitNewLicense(request):
licenseId = licenseRequest.id
serverUrl = request.build_absolute_uri('/')
licenseRequestUrl = os.path.join(serverUrl, reverse('license-requests')[1:], str(licenseId))
statusCode = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType)
statusCode, githubIssueId = utils.createIssue(
licenseAuthorName, licenseName, licenseIdentifier,
licenseComments, licenseSourceUrls, licenseHeader,
licenseOsi, licenseExamples, licenseRequestUrl,
token, urlType)

# If the license text matches with either rejected or yet not approved license then return 409 Conflict
else:
Expand All @@ -172,6 +177,7 @@ def submitNewLicense(request):
data['issueUrl'] = issueUrl

data['statusCode'] = str(statusCode)
data['issueId'] = str(githubIssueId)
return JsonResponse(data)
except UserSocialAuth.DoesNotExist:
""" User not authenticated with GitHub """
Expand Down Expand Up @@ -986,7 +992,10 @@ def promoteNamespaceRequests(request, license_id=None):
if 'urlType' in request.POST:
# This is present only when executing submit license via tests
urlType = request.POST["urlType"]
statusCode = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType)
statusCode, githubIssueId = utils.createIssue(
licenseAuthorName, licenseName, licenseIdentifier,
licenseComments, licenseSourceUrls, licenseHeader, licenseOsi,
licenseExamples, licenseRequestUrl, token, urlType)
return_tuple = (statusCode, licenseRequest)
statusCode = return_tuple[0]
if statusCode == 201:
Expand Down Expand Up @@ -1161,7 +1170,11 @@ def issue(request):
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)
statusCode, githubIssueId = utils.createIssue(
licenseAuthorName, licenseName, licenseIdentifier,
licenseComments, licenseSourceUrls, licenseHeader,
licenseOsi, licenseExamples, licenseRequestUrl, token,
urlType, matchId, diffUrl, msg)
data['statusCode'] = str(statusCode)
return JsonResponse(data)
except UserSocialAuth.DoesNotExist:
Expand Down