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

1008-add-create-branch-from-GitHub-issue-option #1025

Merged
merged 7 commits into from
Oct 29, 2018
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"name" : "MCGitlabRepository"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
requesting
getIssue: owner project: projectName number: issueNumber

^ self get: 'repos/', owner,'/', projectName, '/issues/', (issueNumber asString)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
I'm a panel to create a new branch taking a GitHub issue as basis.
A GitHub issue will be created in the form:

123-a-github-issue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
specs
defaultSpec
<spec: #default>

^ SpecLayout composed
newColumn: [ :col |
col
newRow: #currentBranchLabel height: self inputTextHeight;
newRow: #remotePanel height: self inputTextHeight;
newRow: [ :row |
row
newColumn: #branchLabel width: self iceLabelWidth;
newColumn: #issueNumberText ]
height: self inputTextHeight;
newRow: [ :row |
row
newColumn: #issueLabel width: self iceLabelWidth;
newColumn: #issueText ]
height: self inputTextHeight;
newRow: #spacePanel ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing
icon

^ (self iconNamed: #github) scaledToSize: 16@16
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
title
^ 'New branch from issue'
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing
unknownTitle
^ 'INVALID-ISSUE'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
accessing
branchName

^ '{1}-{2}' format: {
issueNumberText text trim.
issueText text trim }.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
api
extent
^ 800@175
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
initialization
initialize

super initialize.
fetched := false
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
initialization
initializeFocusOrder

self focusOrder
add: remotePanel;
add: issueNumberText;
add: issueText
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
initialization
initializeWidgetsContents
spacePanel := PanelMorph new asSpecAdapter.

self initializeCurrentBranchLabel.

remotePanel := self instantiate: IceTipSelectRemotePresenter on: self selectRemoteModel.
remotePanel remoteList whenSelectedItemChanged: [ :remoteModel |
self useRemote: remoteModel ].

branchLabel := self newLabel label: 'Issue number:'.
issueNumberText := self newTextInput
ghostText: 'e.g., 123';
autoAccept: true.
issueLabel := self newLabel label: 'Title:'.
issueText := self newTextInput
ghostText: 'e.g., 123-github-issue';
autoAccept: true.

issueNumberText whenBuiltDo: [ :w | w widget wrapFlag: false ].
issueText
whenBuiltDo: [ :w |
w widget wrapFlag: false.
w widget enabled: false ].
issueNumberText textHolder whenChangedDo: [ :text | self validateIssue: text ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing ui
issueLabel: anObject
issueLabel := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing ui
issueLabel
^ issueLabel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing ui
issueNumberText: anObject
issueNumberText := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing ui
issueNumberText
^ issueNumberText
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing ui
issueText: anObject
issueText := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing ui
issueText
^ issueText
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing ui
remotePanel: anObject
remotePanel := anObject
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
accessing ui
remotePanel
^ remotePanel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
private
sanitizeTitle: aString
| separators safeSeparator |

aString isEmptyOrNil ifTrue: [ ^ self class unknownTitle ].

safeSeparator := $-.
separators := { Character space. Character tab. $_. safeSeparator }.
^ String streamContents: [ :str |
aString do: [ :c |
(separators includes: c) ifTrue: [ str nextPut: safeSeparator ].
c isAlphaNumeric ifTrue: [ str nextPut: c ] ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
accessing
selectRemoteModel

^ selectRemoteModel ifNil: [
selectRemoteModel := IceTipRemoteActionModel
repositoryModel: self model
on: self model entity ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
private
updateText: aString

issueText text: aString.
fetched := true
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
private
useRemote: aRemoteModel

self selectRemoteModel useRemote: aRemoteModel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
accessing
validate

self
assert: ((issueNumberText text asString notEmpty) and: [ issueNumberText text isAllDigits ])
description: 'Please enter a valid issue number'.

self
assert: fetched
description: 'Please fetch a valid issue number'
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
private
validateIssue: aString
| number remote |

fetched := false.
aString trimmed isEmpty ifTrue: [ ^ self ].
aString isAllDigits ifFalse: [ ^ self ].
number := aString asNumber.
(issue isNil or: [ (issue at: 'number') ~= number ]) ifFalse: [ ^ self ].
remote := self selectRemoteModel remote.

self wait: 500 milliSeconds thenDo: [
[
issue := IceGitHubAPI new
beAnonymous;
getIssue: remote owner
project: remote projectName
number: number.
UIManager default defer: [
self updateText: (self sanitizeTitle: (issue at: 'title')) ] ]
on: IceGitHubError do: [ :e |
e messageText = 'Not Found' ifFalse: [ e pass ].
UIManager default defer: [
self updateText: self class unknownTitle ] ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
private
wait: time thenDo: aBlock
"This method avoids to request too many times the github api.
It does it in the simplest way possible: it starts a process that waits some
time (usually 500 milliseconds). If there is another entry before, it terminates
the process and starts a new one."

currentWaitingProcess ifNotNil: [ currentWaitingProcess terminate ].
currentWaitingProcess := [
time wait.
aBlock value ]
forkNamed: 'GitHub issue tracker'
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"commentStamp" : "EstebanLorenzano 9/18/2018 17:11",
"super" : "IceTipCheckoutNewBranchPanel",
"category" : "Iceberg-Plugin-GitHub-View",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"remotePanel",
"issueNumberText",
"issueLabel",
"issueText",
"issue",
"fetched",
"selectRemoteModel",
"currentWaitingProcess"
],
"name" : "IceGitHubNewBranchFromIssuePanel",
"type" : "normal"
}
4 changes: 4 additions & 0 deletions Iceberg-Plugin-GitHub.package/IceGitHubPlugin.class/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
I'm a pluging to handle GitHub issues integration.
It just add options to easily handle the creation of branchs with the "convention" issue naming format (number-plus-normalised-title):

123-a-sample-of-issue-branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
isAvailableFor: aRepository

^ aRepository remotes anySatisfy: [ :each | each host = 'github.com' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
accessing-ui
checkoutBranchPanelsOnModel: aRepositoryModel

^ { IceGitHubNewBranchFromIssuePanel on: aRepositoryModel }
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "EstebanLorenzano 9/18/2018 17:09",
"super" : "IcePlugin",
"category" : "Iceberg-Plugin-GitHub",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "IceGitHubPlugin",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
testing
browserContextActivation
<classAnnotation>

^ CmdContextMenuActivation
byItemOf: IceGitHubMenuGroup
order: 20
for: IceTipRepositoryListContext
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
canBeExecutedInContext: aToolContext

^ aToolContext repositoryModel remotes anySatisfy: [ :each | each host = 'github.com' ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testing
defaultMenuIconName
^ #branch
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testing
defaultMenuItemName
^ 'Create new branch for issue...'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
testing
defaultPosition

^ #right
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
testing
defaultToolbarItemName
^ 'New issue'
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
execution
defaultMenuIcon

^ self iconNamed: #github
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
execution
execute

(IceTipCheckoutBranchDialog on: self repositoryModel)
withTypes: (IceGitHubPlugin new checkoutBranchPanelsOnModel: self repositoryModel);
openDialogWithSpec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"commentStamp" : "",
"super" : "IceTipCommand",
"category" : "Iceberg-Plugin-GitHub-Commands",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [ ],
"name" : "IceNewBranchFromGitHubIssueCommand",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
acccessing-ui
checkoutBranchPanelsOnModel: anIceTipCachedModel
checkoutBranchPanelsOnModel: aRepositoryModel

^ { IcePharoNewBranchFromIssuePanel on: anIceTipCachedModel }
^ { IcePharoNewBranchFromIssuePanel on: aRepositoryModel }

This file was deleted.